Skip to content

Reject failed and prematurely closed HTTP response bodies - #2568

Open
dajudge wants to merge 1 commit into
actions:mainfrom
dajudge:fix/http-client-response-body-errors
Open

dajudge wants to merge 1 commit into
actions:mainfrom
dajudge:fix/http-client-response-body-errors

Conversation

@dajudge

@dajudge dajudge commented Nov 7, 2026

Copy link
Copy Markdown

Description

Reject failed or prematurely closed HTTP response bodies instead of leaving body-reading promises pending indefinitely.

HttpClientResponse.readBody() and readBodyBuffer() currently listen only for data and end. If a connection fails after response headers arrive, the response can emit an error or close without end, leaving callers waiting indefinitely. This also occurs after a socket timeout destroys the request.

Read both response bodies through a shared stream iterator, which propagates errors and premature closure while preserving the existing string and Buffer return types.

This is separate from #2551, which fixes request/socket cleanup on timeout. With that fix applied, a local post-header timeout reproduction still leaves the original body reader pending; the updated reader rejects with aborted. The download stream pipeline already rejects this scenario, so this PR does not claim to fix archive transfer deadlines.

Tests and validation

  • Add 14 tests covering both readers: complete and empty bodies, stream errors, aborted responses, premature closure after partial data, reading an already-destroyed response, and a real server disconnect after headers and partial data.
  • The initial regression tests reproduced six hangs against unmodified upstream code.
  • All 89 HTTP-client tests passed, along with formatting, lint, and the TypeScript build. The final test-helper cleanup was also rechecked with all 14 new regression tests.

@dajudge
dajudge requested a review from a team as a code owner November 7, 2026 03:47

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant