Repository navigation
fix: drain unconsumed request bodies so keep-alive connections don't hang - #16170
Merged
Rich-Harris merged 2 commits intoJul 2, 2026
Merged
Conversation
…hang When a Node route doesn't read the request body (e.g. a page route receiving a POST), the unread bytes stay buffered in the socket. On keep-alive connections Node's HTTP parser reads those leftover bytes as the next request, fails to parse them, and resets the connection. Resume the request after the response is sent to discard the bytes and keep the connection usable. Closes sveltejs#14916 Closes sveltejs#15526 Co-Authored-By: Claude Opus 4.8 <[email protected]>
🦋 Changeset detectedLatest commit: 9141e4e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
I think this PR may need to target |
commented
Jun 30, 2026
Contributor
Author
Changed target branch from |
Rich-Harris
approved these changes
Jul 2, 2026
This was referenced Jul 2, 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.
closes #14916
closes #15526
Problem
When a Node route doesn't read the request body (e.g. a page route receiving a
POST), the unread bytes stay buffered in the socket. On keep-alive connections Node's HTTP parser reads those leftover bytes as the next request, fails to parse them, and resets the connection — losing any pipelined request.Because
get_raw_bodyattaches adatalistener, Node marks the request as consumed (req._consuming) and skips its own automatic drain, so we have to do it ourselves.Fix
After the response is sent (
finish/close),drain_requestremoves the lingeringdatalistener and callsreq.resume()to discard the remaining bytes, keeping the connection usable. Theend/errorlisteners stay attached so the body'sReadableStreamis still closed/errored, and a consumer that stopped reading mid-body sees a clean end instead of hanging.Tests
Added unit tests in
packages/kit/src/exports/node/index.spec.jscovering:draining an unconsumed body (content-length and chunked)
draining the remainder of a partially consumed body
closing the body stream after draining
Tests added
Changeset added (
patch)Edits