Skip to content

KTOR-9946 Curl, Apache5: Fail in-flight requests when the client is closed - #5910

Open
Ruslan Ibrahimau (IRus) wants to merge 2 commits into
ktorio:mainfrom
IRus:fix/curl-close-pending-requests
Open

Ruslan Ibrahimau (IRus) wants to merge 2 commits into
ktorio:mainfrom
IRus:fix/curl-close-pending-requests

Conversation

@IRus

Copy link
Copy Markdown
Contributor

Closing the client stopped the event loop and cleaned up the easy handles without completing their response deferreds or closing their body channels, so pending requests and body readers hung forever.

Remove each remaining handle through removeEasyHandle with ClientEngineClosedException. It fails a request that waits for headers and closes the body channel of a response that is still streaming.

Subsystem
Client. Curl

Motivation
https://youtrack.jetbrains.com/issue/KTOR-9946/Curl-In-flight-requests-hang-forever-after-the-client-is-closed

Solution
On close, fail each remaining request with ClientEngineClosedException

Closing the client stopped the event loop and cleaned up the easy handles
without completing their response deferreds or closing their body
channels, so pending requests and body readers hung forever.

Remove each remaining handle through removeEasyHandle with
ClientEngineClosedException. It fails a request that waits for headers
and closes the body channel of a response that is still streaming.
Closing the client closed the Apache client with CloseMode.IMMEDIATE.
Apache does not reliably call failed() on the exchanges it drops, so the
response deferred and the body channel were never completed, and pending
requests and body readers hung forever.

Each request now registers a handler on the engine job that fails its
response consumer with ClientEngineClosedException. The engine job
completes in close() before the Apache client is closed. This fails a
request that waits for headers and closes the body channel of a response
that is still streaming. The handler is disposed when the call completes.
@IRus Ruslan Ibrahimau (IRus) changed the title KTOR-9946 Curl: Fail in-flight requests when the client is closed KTOR-9946 Curl, Apache5: Fail in-flight requests when the client is closed Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant