Repository navigation
Conversation
…body When the connection drops after the response headers were received, the error from the response body stream was not forwarded (`.pipe()` ignores source errors). It surfaced as an uncaughtException and the request promise never settled. Destroy the output stream with the source error so it reaches the request duplex (and the transport promise rejects), and handle the resulting readAll() rejection in the response handler. Fixes jsforce#1852
Arestout
force-pushed
the
fix/stream-error-mid-body
branch
from
November 2, 2026 16:15
e04e553 to
423a257
Compare
Arestout
marked this pull request as ready for review
November 2, 2026 16:15
|
This also fixes Bulk API v2 query result downloads. I tested the PR against a local server that sends part of a
The new tests and the Could a maintainer take a look? Thanks |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1852
Outcome
conn.query(),search(),limits(),request()and other calls now reject with the socket error (TypeError: terminated, causeUND_ERR_SOCKET).uncaughtException, which crashes Node processes that have no handler, and the returned promise never settled.Design
src/request.ts:Readable.fromWeb(res.body).pipe(output)ignored errors from the source stream, because.pipe()does not forward them. The source stream now has an error listener that callsoutput.destroy(err).outputis the readable half of the request duplex, and that duplex already forwards its errors (DuplexifiedStreaminsrc/util/stream.ts). So the error reaches the duplexerrorevent once, andTransportalready rejects on that event.src/request-helper.ts: theresponsehandler catches the rejection fromreadAll(). That rejection is the same error the duplex has already emitted, so catching it only stops a second, unhandled rejection.stream.pipeline(). It would also destroyoutputwith the error, but it requires a callback, and that callback would either report the error a second time or be an empty no-op.Verification
test/http-api.test.ts. They are node-only and run against a real localnode:httpserver that sends headers and part of the body, then drops the connection:conn.query()promise rejects withterminated/UND_ERR_SOCKET, and jest reports no uncaught exception or unhandled rejection;request()stream emitserrorand does not emitend.main(unhandledterminatederror plus a 3 s timeout) and pass with the fix. Each of the two source changes is needed for them to pass.uncaughtException: terminated, andquery()was still pending after 5 s;query() rejected: terminated | cause: UND_ERR_SOCKET;eslint src test: clean;tsc -p test: clean;jest test/http-api.test.ts: 58/58 passed;Known limitation (not changed here)
conn.request(...).stream()usescreateLazyStream(src/util/stream.ts), which connects its streams with.pipe(). So after a mid-body drop that stream gets noerrorevent, although the promise now rejects. Errors that happen before the headers arrive already behave this way today. Fixing it belongs in a separate change.