Repository navigation
End the response with disconnectStatusCode when the client disconnects - #4596
Open
SahinurDEV wants to merge 1 commit into
Open
SahinurDEV wants to merge 1 commit into
SahinurDEV wants to merge 1 commit into
Conversation
When the client went away before hapi replied, the native response was never ended, and a response 'close' without a request 'aborted' (e.g. a GET whose payload was fully read, or a disconnect during onPreResponse) was reported with the handler's 200 instead of the disconnect error. Treat response 'close' like 'aborted', report a disconnect during onPreResponse as the disconnect error, and end the native response with that status code so http instrumentation sees the request finish. Fixes hapijs#4244 Assisted-by: Grok Bot
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.
Fixes #4244.
When the client disconnects before hapi replies, two things go wrong:
res.end()is never called, so http instrumentation (e.g. OpenTelemetry) never sees the request finish. On master,curl --max-time 1against the route in the issue logs a 499'response'event butres.endis not called.'close'with no request'aborted'(for example, the payload was fully read, or the client leaves duringonPreResponse), the request is still reported with the handler's 200.Changes in
lib/request.js:'close'before the reply is handled the same way as'aborted': reply with thedisconnectStatusCodeerror and emit'disconnect'.onPreResponsereplaces the response with that error. The original response is kept indata._abort()now ends the native response with the error's status code. It only skipped this before forh.close, and it still skips it forh.abandon.API.md already describes
disconnectStatusCodeas applying when "the request is closed or aborted", so the docs don't change.Tests: three new cases in
test/request.js(abort during handler, close after full payload with a customdisconnectStatusCode, disconnect duringonPreResponse). All three fail on master.Payload handles request socket closenow expects 499 instead of 500.npm testgives 1009 tests, 100% coverage, lint and types clean.AI disclosure: I used Grok Bot to help trace the lifecycle and write the tests. The commit has an
Assisted-by:trailer. I ran the full suite and the issue's curl repro locally before and after the change.