KTOR-9946 Curl, Apache5: Fail in-flight requests when the client is closed - #5910
Open
Ruslan Ibrahimau (IRus) wants to merge 2 commits into
Open
Ruslan Ibrahimau (IRus) wants to merge 2 commits into
Ruslan Ibrahimau (IRus) wants to merge 2 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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