Fix req end during response transmission #4264
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.
Addresses #4262. On node v16 hapi would cut short any response that was transmitting while the request stream ended. This is not especially common, partly because the request stream is often used prior to transmitting the response, and partly because this case does not apply when the request stream is not read at all i.e. for GET requests.
I believe this change is sound and backwards compatible because on node versions prior to v16, both req and res
'close'
events have identical meaning: the underlying connection shared by req and res has closed. For this reason, there is no need to add listeners to both req and res on node <v16.Starting with node v16 the
'close'
event for req no longer relates to the underlying connection, best documented at nodejs/node#38924 and nodejs/node#33035. This means that it is possible for req to'close'
prior to res, notably while transmitting res. The change in this PR is intended to take that into account. The test added here was failing on node v16 prior to this change.See also #4263, which fixes a test that would have failed with the changes made in this PR.