RequestBag keeps the request body after an early response with status >= 300

未关闭
#941 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@beshkenadze 已经在做这个了。

开始于 2026年10月22日。

  • #945 来自 @beshkenadze —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
swift

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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
主要语言
Swift
星标
1.1k
派生
159
平均合并
2 小时 56 分钟
30 天内合并 PR
1

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

swift-server/async-http-client 的其他 Issue

查看 swift-server/async-http-client 的全部 Issue

相似的 Issue

更多 Swift Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。