fix(ext/node): don't emit ServerResponse 'finish' after client abort#34026
Merged
Conversation
When the client aborts an HTTP request before `res.end()` runs, the server-side socket fires its `'close'` event which calls `emitCloseNT` on the in-flight `ServerResponse`, setting `destroyed = true`. The deferred `res.end()` then schedules `onFinish` via the `_send` callback, which only checked `socket._hadError` - that flag isn't set on the abort path in Deno, so `'finish'` was still emitted after `'close'`. Node only emits `'close'` in this scenario. Guard `onFinish` against a destroyed response (or socket) so we match Node's behavior. Fixes #34002
bartlomieju
approved these changes
May 14, 2026
littledivy
pushed a commit
to crowlKats/deno
that referenced
this pull request
Jun 10, 2026
…enoland#34026) Fixes denoland#34002. Co-authored-by: lunadogbot <[email protected]>
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.
Summary
Fixes #34002.
When the client aborts an HTTP request before
res.end()runs, theserver-side socket fires its
'close'event, which callsemitCloseNT(res)on the in-flightServerResponse.emitCloseNTsetsdestroyed = true/_closed = trueand emits'close'. The deferredres.end()then schedulesonFinishvia the_sendcallback,and
onFinishonly checkedsocket._hadError— that flag is not set onthe abort path in Deno, so
'finish'was emitted after'close'.Node emits only
'close'in that scenario.This PR adds a
destroyedguard toonFinishso the response stopsemitting
'finish'once it has already been destroyed (either via theresponse or its socket).
Reproducer (from #34002)
Before (Deno 2.7.14 release):
After (Node, and Deno with this fix):
Test plan
tests/unit_node/http_test.tsregression test"[node/http] ServerResponse does not emit 'finish' after client abort"ServerResponsetests still pass (deno test -A tests/unit_node/http_test.ts --filter "ServerResponse")tools/format.jscleantools/lint.js --jscleanCloses bartlomieju/orchid-inbox#47