Repository navigation
fetch: settle buffered body promises when an aborted request still has a streaming request body - #32130
Conversation
…s a streaming body When a fetch with an in-flight ReadableStream request body was aborted after response headers arrived, the terminal failure callback returned right after cancelling the request-body sink and never errored the response body value. A pending arrayBuffer()/text()/json() promise then stayed unsettled forever, permanently leaking the request. Error the buffered body before cancelling the sink (cancel runs the stream's JS cancel callback synchronously, so it goes last). Also restore the HTTP-thread debug+ASAN check that every abort-tracker socket pointer is alive around each loop tick; the Zig implementation had this and the port dropped it.
|
Updated 1:52 PM PT - Jun 11th, 2026
❌ @robobun, your commit b3da0d7 has 1 failures in
🧪 To try this PR locally: bunx bun-pr 32130That installs a local version of the PR into your bun-32130 --bun |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
WalkthroughThis PR fixes a promise-pending hang when aborting a fetch request that has a streaming request body. The core fix reorders error handling in ChangesFetch abort with streaming request body
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
|
CI status: the new test passes on every lane in both runs. The remaining red is unrelated to this diff:
This change only touches the fetch failure path ( |
Repro
await pnever settles. The request is leaked permanently: under load (a client that uploads while downloading and aborts, e.g. proxies or streaming API clients), every such abort strands one request, and once enough accumulate all later fetches hang too.Cause
When the HTTP thread fails an in-flight request (abort, timeout, connection error),
FetchTasklet::on_body_receivedhandles the terminal failure result. If the request body was a JSReadableStreamwhose sink was still active, the failure path did:The early return skipped the
current_response_mut()branch that rejects a buffered body promise (arrayBuffer/text/json), so that promise stayed pending forever. Failure results are terminal (to_resultforceshas_more = falseoncefailis set), so no later update can ever settle it. The bug only triggers when the response arrives while the upload stream is still open; consumers readingres.bodydirectly were unaffected (the readable-stream branch above it errors the stream before the early return).This was ported faithfully from the Zig implementation, which has the same early return, so 1.3.x releases are affected too.
Fix
Remove the early return: materialize the error for the sink, reject the buffered response body, and cancel the sink last (
ResumableSink::cancelinvokes the stream's JS cancel callback synchronously viarun_callback, so it runs after the tasklet state is settled).Also restores the HTTP-thread debug+ASAN assertion (present in the Zig implementation, dropped in the port) that every socket pointer in the abort tracker points at live memory, checked around each loop tick. A stale entry there is the likely mechanism behind a family of release-build segfaults in
drainQueuedShutdowns -> us_internal_ssl_socket_close -> us_internal_set_loop_ssl_datareported from 1.3.x builds; with the assertion back, any close path that forgetsunregister_abort_trackerfails loudly in debug CI at the tick that leaked instead of segfaulting at a later abort.Verification
New test
test/js/web/fetch/fetch-abort-stream-body.test.ts("abort mid-response rejects buffered body promises while the request body stream is active") runs the repro in a subprocess fixture for botharrayBuffer()andtext().USE_SYSTEM_BUN=1, also reproduced on 1.3.14): fixture printsarrayBuffer timed out/text timed out, test fails in ~2.5s.AbortError, test passes.A stress run (60 concurrent workers doing this shape in a loop) wedged every worker within seconds on the unfixed build and completes cleanly on the fixed one. The wedge reproduces identically on bun 1.3.14, and ~200k aborted-fetch iterations across keepalive/redirect/proxy/TLS/h2 variants ran clean under ASAN with the restored tracker assertion enabled.