Repository navigation
KTOR-9938: Apache5: Abort the exchange when data arrives for a cancelled body channel - #5906
Open
Ruslan Ibrahimau (IRus) wants to merge 1 commit into
Open
Ruslan Ibrahimau (IRus) wants to merge 1 commit into
Ruslan Ibrahimau (IRus) wants to merge 1 commit into
Conversation
…ed body channel When the execute block returned before the body arrived, the response channel was cancelled and consume() discarded incoming data without returning capacity. Apache then stopped reading, the stream never ended, and the consumer job never completed, so execute() hung. Cancelling the consumer job aborts the exchange through attachFuture.
Osip Fatkullin (osipxd)
self-requested a review
September 25, 2026 18:08
Osip Fatkullin (osipxd)
requested changes
Sep 29, 2026
| class Apache5UnreadBodyTest { | ||
|
|
||
| @Test | ||
| fun `streaming response completes when the body arrives after the block returns`() = runTest(timeout = 10.seconds) { |
There was a problem hiding this comment.
While reviewing this PR I managed to write a common test case that checks this behavior for all client engines. And after writing these tests I found some more cancellation-related problems affecting all client engines (KTOR-9943) 😓
I think we should merge #5913 first and after that you'll be able to remove this test and just remove except("Apache5") from cancelling rawContent stops the underlying stream test.
Contributor
Author
There was a problem hiding this comment.
Sure, I can do it
There was a problem hiding this comment.
#5913 merged into release/3.x
There was a problem hiding this comment.
You can switch the base branch using ./switch-base-branch.sh script
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.


When the execute block returned before the body arrived, the response channel was cancelled and consume() discarded incoming data without returning capacity. Apache then stopped reading, the stream never ended, and the consumer job never completed, so execute() hung. Cancelling the consumer job aborts the exchange through attachFuture.
Subsystem
Client, Apache5 engine
Motivation
https://youtrack.jetbrains.com/issue/KTOR-9938/Apache5-streaming-response-hangs-when-the-block-returns-before-the-body-arrives
Solution
Abort the request when nobody reads the body anymore, instead of hanging