fix: premature request.signal abort on POST#6725
Open
bausmeier wants to merge 5 commits into
Open
Conversation
In preparation for adding a test which passes a signal to the timeout.
The 'close' event on the raw IncomingMessage fires both when the request body stream is fully consumed and when the underlying connection is aborted. The handlerTimeout abort listeners treated every close as a disconnect, so POST requests with a body had their request.signal aborted as soon as the body finished streaming, and before the handler had a chance to use it. Guard both onAbort listeners with an aborted check on the IncomingMessage so the signal only aborts when the client genuinely disconnects, leaving normal body completion alone.
mcollina
reviewed
May 14, 2026
Avoid shadowing the global setTimeout.
Make it very clear that the abort is not a result of the timeout.
The onAbort handler unconditionally cleared the handler timeout timer whenever the underlying request emitted 'close', including the normal end-of-body close on POST requests. This caused the handler timeout to be cancelled before the slow handler had a chance to time out, so clients received no FST_ERR_HANDLER_TIMEOUT response. Only clear the timer when the request was actually aborted, and add a regression test covering a slow POST handler with a request body.
Author
|
I found another scenario which my fix hadn't catered for. I've now fixed that too and added an additional test. |
metcoder95
approved these changes
May 18, 2026
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
I ran into a bug when trying to use the
handlerTimeoutoption introduced in #6521.I managed to narrow it down to only requests with bodies, and did some debugging to identify the root cause from there.
What it boils down to is that the 'close' event on the raw
IncomingMessagefires both when the request body stream is fully consumed and when the underlying connection is aborted. ThehandlerTimeoutabort listeners treated every close as a disconnect, so POST requests with a body had theirrequest.signalaborted as soon as the body finished streaming, and before the handler had a chance to use it.This fix guards the
onAbortlisteners with an aborted check on theIncomingMessageso the signal only aborts when the client genuinely disconnects, leaving normal body completion alone.Checklist
npm run test && npm run benchmark --if-presentand the Code of conduct