RequestBag keeps the request body after an early response with status >= 300
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- swift
- Domain
- backend-api-design
Research direction
Start with HTTPRequestStateMachine and the request body stream handling when a response head has status 300 or higher; trace how the channel handler releases the request when the response ends. Read RequestBagTests.swift and HTTP1ClientChannelHandlerTests.swift, then run the focused testUploadIsCancelledIf and testUploadResumesIfResponseBelow300 tests. Done means the task and pending write futures complete after the response, and a later body write fails with requestStreamCancelled. The async/await Transaction case is tracked in #939.
Written by the indexing model from the issue text.
Description
AsyncHTTPClient commit hash: 017115279d09dbfd262a6c678e96d31c90b3b2aa (main)
Context
The caller uses HTTPClient.execute(request:delegate:) or an EventLoopFuture method that calls it, for example post(url:body:). The request has an HTTPClient.Body.stream body. The server sends a complete >= 300 response, for example 401 or 413, before the request body ends.
At a >= 300 response head, HTTPRequestStateMachine pauses the request body stream and does not resume it. When the response ends, the channel handler releases the request. No later event completes the write future. The body writer waits forever.
The write future callbacks keep these items in memory:
- the
RequestBag - the delegate
- the data that the body writer holds
The async/await API (Transaction) has the same bug: #939.
Steps to reproduce
The tests use EmbeddedEventLoop and EmbeddedChannel and open no network connections.
These commands add only the new tests from https://github.com/beshkenadze/async-http-client/tree/fix/requestbag-stop-request-body-after-early-response. The library sources stay at 0171152.
git clone https://github.com/swift-server/async-http-client.git
cd async-http-client
git checkout 017115279d09dbfd262a6c678e96d31c90b3b2aa
git fetch https://github.com/beshkenadze/async-http-client.git fix/requestbag-stop-request-body-after-early-response
git checkout FETCH_HEAD -- Tests/AsyncHTTPClientTests/RequestBagTests.swift Tests/AsyncHTTPClientTests/HTTP1ClientChannelHandlerTests.swift
swift test --filter 'testUploadIsCancelledIf|testUploadResumesIfResponseBelow300'
Expected result
After the delegate consumes the complete response, the task succeeds with the response. Each write future completes. A later body write fails with HTTPClientError.requestStreamCancelled.
Actual result
4 of 5 tests fail. RequestBagTests.testUploadResumesIfResponseBelow300EndsWhileUploadIsPaused (status 200) passes.
Test (testUploadIsCancelledIf...) |
State when the 413 response ends | Result |
|---|---|---|
RequestBagTests ...ResponseAtLeast300EndsWhileUploadIsPaused |
The delegate consumed the response. A body write waits. | The task and the write future do not complete. |
HTTP1ClientChannelHandlerTests ...ResponseAtLeast300EndsWhileUploadIsPaused |
Same, through the HTTP/1 channel handler. | The write future does not complete. |
RequestBagTests ...ResponseAtLeast300EndsWhileWaitingForNextBodyPart |
The delegate consumed the response. No body write waits. | The task does not complete. The next body write goes to the executor, and its future does not complete. |
RequestBagTests ...BufferedResponseAtLeast300EndsWhileUploadIsPaused |
The delegate did not consume the response yet. The RequestBag buffers the response body. A body write waits. |
The task succeeds. The write future does not complete. |
Versions
- OS: macOS 27.0.1 (26A434)
$ swift --version
swift-driver version: 1.168.6 Apple Swift version 6.4 (swiftlang-6.4.0.34.1 clang-2100.3.34.1)
Target: arm64-apple-macosx27.0.0
$ uname -srvm
Darwin 27.0.0 Darwin Kernel Version 27.0.0: Tue Aug 11 21:22:49 PDT 2026; root:xnu-13432.1.9~1/RELEASE_ARM64_T6000 arm64
- Dominant language
- Swift
- Stars
- 1.1k
- Forks
- 159
- Avg merge
- 18h 43m
- Merged PRs (30d)
- 2
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from swift-server/async-http-client
-
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
swift-server/async-http-client#950 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
swift-server/async-http-client#946 · 2 comments ·
-
HTTP/2 stream stays half-closed after an early response with status >= 300Possibly taken @beshkenadze claimed this 28 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
Transaction keeps the request body after an early response with status >= 300Possibly taken @beshkenadze claimed this 28 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 22/100
All issues in swift-server/async-http-client
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Ranchero-Software/NetNewsWire#5572 ·
Maintainers usually reply within 11 days
-
api beginner story
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
NCSU-App-Development-Club/ios_fall_26#86 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
yetanotherbrowser/yab#1008 ·
Maintainers usually reply within 2 days
-
Difficulty 1/5 1-3 hours Newbie friendliness 90/100