fix: handle streamed response failure - #1861
Open
bigujun wants to merge 1 commit into
Open
Conversation
4 tasks
iffa
added a commit
to iffa/tsoa
that referenced
this pull request
Aug 24, 2026
readable.pipe(response) leaves the stream's error event unhandled, so a Readable destroyed with an error took the whole node process down. pipeline handles the error and destroys the response, which aborts the request. The error also goes to express's next() so an application can log it; a client that hangs up mid-stream is not reported. A 500 is not reachable here - pipeline destroys the response before its callback runs - so the request aborts instead. Upstream lukeautry#1861 discards the error.
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.
Node process crashes with
Uncaught Errorwhen a readable stream is destroyed with an error when using express.Reproduce steps:
One workaround is to watch for the error event and manually close the underlying connection.
The problem is that
readable.pipe(...)does not properly handle errors, so replacing it with pipeline solves the problem, since pipeline will properly clean up.All Submissions:
Closing issues
closes #1664
Test plan
Included an express integration test that fails when the patch is not applied.
Test case simulates a readable that will be destroyed with an error and expects the connection to be aborted.
Without the fix applied, the process will throw an
Uncaught Errorand test will fail.With the fix applied, the connection will be properly aborted and test will pass.