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

Đang mở
#941 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

@beshkenadze đang làm issue này rồi.

Từ ngày 22/10/2026.

  • #945 của @beshkenadze — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
swift
Lĩnh vực
backend-api-design

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
Swift
Star
1.1k
Fork
159
Merge trung bình
2 giờ 56 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của swift-server/async-http-client

Tất cả issue của swift-server/async-http-client

Issue tương tự

Thêm issue về Swift

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.