Handle stream.destroy() called before stream end #4552
Merged
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.
It seems that hapi has a major issue with stream responses, where
stream.destroy()is called on it before it has ended. More specifically, it will essentially ignore thedestroy(), and never end the response stream (unless a server timeout has been configured). Since users control the stream they return, it is likely that this can happen for them.The main fix is to treat stream
'close'as an aborted response.A secondary fix is need to handle when the stream is internally piped through eg. a compressor. This is because
stream.pipe()only forwards the'end'event, which never happens once destroyed.Note that it is only the first test that exposes the breakage. The second test is for added test coverage (and verification).
I haven't checked if this fix has any impact on #4244.