Disable node-fetch gzip on token request to fix ERR_STREAM_PREMATURE_CLOSE#103
Open
spencerhunter wants to merge 2 commits into
Open
Disable node-fetch gzip on token request to fix ERR_STREAM_PREMATURE_CLOSE#103spencerhunter wants to merge 2 commits into
spencerhunter wants to merge 2 commits into
Conversation
Pass `compress: false` on all node-fetch requests (token exchange in Auth.js and the get/post/delete API calls in Token.js) so node-fetch skips the Gunzip pipeline that surfaces false-positive ERR_STREAM_PREMATURE_CLOSE errors on keep-alive sockets under Node.js v24.17.0+ (see nodejs/node#63989). Bump version to 3.4.2, sync package-lock.json, and update the changelog.
Customer reports (production and sandbox) show every failure occurs at the /token fetch before any downstream API call runs; the Token.js data calls were never reached. Revert compress:false there to preserve gzip on large API responses, and keep it only on the OAuth token request where the payload is tiny and compression provides no benefit.
Member
Author
Reproduction & fix verificationReproduced the bug and verified the fix end-to-end against the live sandbox token endpoint on the first affected Node version. Environment
Before fix (no Failed on the very first request — matches both customer reports (production + sandbox). After fix ( Same Node version, endpoint, and credentials between runs; the only difference was the one-line Repro script (run with Node ≥ 24.17.0; not committed to the repo)// Reproduces ERR_STREAM_PREMATURE_CLOSE against the Dwolla token endpoint.
// Requires Node >= 24.17.0. Uses the local SDK source so toggling the fix in
// src/dwolla/Auth.js changes behavior without reinstalling.
const { Client } = require("./src/index.js");
const ITERATIONS = parseInt(process.env.ITERATIONS || "200", 10);
const client = new Client({
key: process.env.DWOLLA_KEY,
secret: process.env.DWOLLA_SECRET,
environment: process.env.DWOLLA_ENV || "sandbox"
});
(async () => {
let ok = 0;
for (let i = 0; i < ITERATIONS; i++) {
try {
await client.auth.client(); // POST /token, uncached, reuses keep-alive socket
ok++;
process.stdout.write(`ok ${ok}/${ITERATIONS}\r`);
} catch (err) {
console.error(`\nFAILED on iteration ${i}: ${err.code || ""} ${err.message}`);
process.exit(1);
}
}
console.log(`\nAll ${ITERATIONS} token requests succeeded — no premature close.`);
})();Run: |
lochnesh
approved these changes
Jun 23, 2026
|
Tick the box to add this pull request to the merge queue (same as
|
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.
Summary
Passes
compress: falseon the OAuth token request insrc/dwolla/Auth.jsso node-fetch skips the gunzip pipeline that surfaces false-positiveERR_STREAM_PREMATURE_CLOSEerrors.Node.js v24.17.0+ changed
http.Agentkeep-alive socket teardown timing (response queue poisoning fix), which exposes a latentnode-fetch@2bug: gzip + chunked responses read over a reused keep-alive socket raise a premature-close error from the Gunzip stream even though the full payload arrived. See nodejs/node#63989.Verified against node-fetch 2.7.0 source —
compress: falseboth omits theAccept-Encodingrequest header (lib/index.js:1359, so the upstream returns an uncompressedContent-Lengthbody) and skips thezlib.createGunzip()decode path (lib/index.js:1664).Scope: token endpoint only
Two customer reports (production
api.dwolla.comand sandboxapi-sandbox.dwolla.com) show every failure occurs at the/tokenfetch, before any downstream API call runs — e.g. agetOrCreateDwollaCustomercall errors out during token retrieval. "Multiple API calls affected" means many features broke because each needs a token first; theToken.jsdata-call fetches (get/post/delete) were never reached and show no evidence of being affected.The fix is therefore scoped to the token request only:
Changes
compress: falseto the token request inAuth.jspackage-lock.json(was stale at 3.4.0)Testing
main(a Node v22/nock stream incompatibility in the test harness), not introduced by this change