You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
teeny-request throws when response handler destroys the request stream #8670
On Node.js 24.16.0 this reports an unhandled rejection:
Error [ERR_STREAM_UNABLE_TO_PIPE]: Cannot pipe to a closed or destroyed stream
Steps and root cause
Start consuming the stream returned by teenyRequest().
Destroy that stream from its response event handler. Retry wrappers do this when discarding a response before another attempt.
teeny-request then runs its later response listener and calls pipeline(responseStream, requestStream) with the destroyed destination.
Node rejects the pipeline setup with ERR_STREAM_UNABLE_TO_PIPE; the rejection is not handled, and the response body is not disposed.
The stream-mode implementation defers piping until both reading has begun and the fetch response exists, but it does not recheck whether the returned request stream was destroyed by an earlier response listener.
Expected behavior
If the consumer destroys the returned stream before piping starts, teeny-request should skip pipeline construction and destroy the unused response body. No unhandled rejection should escape.
We independently confirmed this issue in production on Cloud Run through @google-cloud/[email protected] -> [email protected]. A deterministic reproduction exits cleanly on Node 22.16.0 but produces the exact ERR_STREAM_UNABLE_TO_PIPE failure on Node 24.15.0 after the consumer destroys the request stream before the delayed response is piped.
Google's fix is now open as #9160. I added our production trace, runtime comparison, downstream workaround, and alternatives analysis there: #9160 (comment)
🤖 Claude Opus 5.5 responding on behalf of wally-tribute-labs
This still reproduces on the latest releases, @google-cloud/[email protected] → [email protected] on Node 24.22.1. No caller code is needed to trigger it: a single retryable 503 on a streamed read is enough. The library's own retry destroys the first request stream, then teeny-request's deferred pipeline() throws and the process exits.
Repro against a local fake GCS endpoint (first response 503, second 200):
importhttpfrom'node:http'import{Storage}from'@google-cloud/storage'lethits=0constserver=http.createServer((req,res)=>{hits++if(hits===1){res.writeHead(503,{'content-type': 'application/json'})res.end('{"error":{"code":503,"message":"backend error"}}')}else{res.writeHead(200,{'content-type': 'application/octet-stream'})res.end('abc')}})awaitnewPromise((r)=>server.listen(0,'127.0.0.1',r))conststorage=newStorage({apiEndpoint: `http://127.0.0.1:${server.address().port}`,projectId: 'repro',})conststream=storage.bucket('b').file('o').createReadStream({validation: false})try{forawait(const_ofstream){}}catch(err){console.log('caught by caller:',err.message)// never reached}
Output (exit code 1):
Error [ERR_STREAM_UNABLE_TO_PIPE]: Cannot pipe to a closed or destroyed stream
at pipelineImpl (node:internal/streams/pipeline:264:15)
at pipeline (node:internal/streams/pipeline:183:10)
at PassThrough.<anonymous> (node_modules/teeny-request/build/src/index.js:461:43)
at PassThrough.wrapper (node:events:639:12)
at PassThrough.emit (node:events:526:24)
at node_modules/teeny-request/build/src/index.js:474:27
We hit this in production on Cloud Run under Deno 2.9's Node compatibility layer (@google-cloud/[email protected] → [email protected]). There it surfaced as Uncaught (in promise) TypeError: k is not a constructor (Deno's rendering of the same throw) and exited the server instance, taking unrelated in-flight work with it. Until #9160 ships, our workaround is a process-level unhandledrejection handler.
Still reproducible with teeny-request 11.1.1, reached through @google-cloud/storage 8.4.0 (retry-request 9.1.0, node-fetch 3.3.2, Node.js 24.16.0), with default retry options.
Trigger in our case: a local HTTP server answers the first alt=media GET of file.createReadStream() with 503 and the second with 200. The download succeeds, but process.on('unhandledRejection') receives ERR_STREAM_UNABLE_TO_PIPE: Cannot pipe to a closed or destroyed stream: retry-request destroys the first attempt's request stream on the retryable response, and teeny-request's once('response') handler then calls pipeline() into it. file.download() shows the same rejection, since it uses the same stream.
Workaround that avoids it for us: retryOptions: { autoRetry: false } on the Storage client (one request, a clean 503 error).
Activity
dich-bandana commentedon Aug 24, 2026
We independently confirmed this issue in production on Cloud Run through
@google-cloud/[email protected]->[email protected]. A deterministic reproduction exits cleanly on Node 22.16.0 but produces the exactERR_STREAM_UNABLE_TO_PIPEfailure on Node 24.15.0 after the consumer destroys the request stream before the delayed response is piped.Google's fix is now open as #9160. I added our production trace, runtime comparison, downstream workaround, and alternatives analysis there: #9160 (comment)
wally-tribute-labs commentedon Oct 28, 2026
Note
🤖 Claude Opus 5.5 responding on behalf of wally-tribute-labs
This still reproduces on the latest releases,
@google-cloud/[email protected]→[email protected]on Node 24.22.1. No caller code is needed to trigger it: a single retryable 503 on a streamed read is enough. The library's own retry destroys the first request stream, thenteeny-request's deferredpipeline()throws and the process exits.Repro against a local fake GCS endpoint (first response 503, second 200):
Output (exit code 1):
We hit this in production on Cloud Run under Deno 2.9's Node compatibility layer (
@google-cloud/[email protected]→[email protected]). There it surfaced asUncaught (in promise) TypeError: k is not a constructor(Deno's rendering of the same throw) and exited the server instance, taking unrelated in-flight work with it. Until #9160 ships, our workaround is a process-levelunhandledrejectionhandler.ScalingMBA commentedon Nov 4, 2026
Still reproducible with
teeny-request11.1.1, reached through@google-cloud/storage8.4.0 (retry-request9.1.0,node-fetch3.3.2, Node.js 24.16.0), with default retry options.Trigger in our case: a local HTTP server answers the first
alt=mediaGET offile.createReadStream()with503and the second with200. The download succeeds, butprocess.on('unhandledRejection')receivesERR_STREAM_UNABLE_TO_PIPE: Cannot pipe to a closed or destroyed stream:retry-requestdestroys the first attempt's request stream on the retryable response, and teeny-request'sonce('response')handler then callspipeline()into it.file.download()shows the same rejection, since it uses the same stream.Workaround that avoids it for us:
retryOptions: { autoRetry: false }on theStorageclient (one request, a clean 503 error).