Repository navigation
fix(storage): handle early stream destruction in createReadStream - #9586
Open
thiyaguk09 wants to merge 9 commits into
Open
thiyaguk09 wants to merge 9 commits into
thiyaguk09 wants to merge 9 commits into
Conversation
…ing up rawResponseStream in file.createReadStream
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces robust error handling and resource cleanup when piping streams in File.ts, specifically addressing scenarios where the target stream is already destroyed or when an ERR_STREAM_UNABLE_TO_PIPE error is thrown. Corresponding unit tests have been added to verify these behaviors. The feedback suggests correcting a TypeScript type cast from RequestError to any (or a generic error type with a code property) to avoid potential compilation issues and semantic inaccuracy, as the error is a standard Node.js stream error.
…e stream handling
thiyaguk09
marked this pull request as ready for review
October 9, 2026 07:33
kalragauri
reviewed
Oct 20, 2026
…ates during read stream cleanup
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.
Description
Prevents an unhandled
ERR_STREAM_UNABLE_TO_PIPEexception inFile#createReadStreamwhen the downstream stream is destroyed or closed before the GCS HTTP response arrives.Impact
Eliminates process crashes caused by synchronous
ERR_STREAM_UNABLE_TO_PIPEerrors thrown inside the asynchronous response callback when a downstream consumer disconnects early, while ensuring the underlying HTTP response stream is properly cleaned up to prevent memory or socket leaks.Changes
throughStream.destroyedinFile#createReadStream's response handler before invokingpipeline(), destroying or drainingrawResponseStreamand returning early if the destination stream is already destroyed.pipeline()call in atry...catchblock to catchERR_STREAM_UNABLE_TO_PIPE, suppress the pipeline completion error handler, safely destroy or drainrawResponseStream, and swallow the error while rethrowing any other unexpected errors.Testing
handwritten/storage/test/file.tsverifying thatrawResponseStreamis destroyed andpipeline()is not called whenthroughStreamis already destroyed before the response callback runs.handwritten/storage/test/file.tsverifying that anERR_STREAM_UNABLE_TO_PIPEerror thrown bypipeline()is caught and swallowed and thatrawResponseStreamis destroyed.Fixes #7603