Repository navigation
fix(mock): drain unread stream request bodies after replying - #5962
Open
TonyWu2333 wants to merge 2 commits into
Open
TonyWu2333 wants to merge 2 commits into
TonyWu2333 wants to merge 2 commits into
Conversation
The mock never reads a stream request body unless the handler has onBodySent/onRequestSent, so with pipeline() a body bigger than the highWaterMark blocks on backpressure and the pipeline never finishes. Resume the body once the reply is sent, and ignore its errors since the response is already done. Fixes: nodejs#2791
metcoder95
approved these changes
Oct 8, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5962 +/- ##
==========================================
+ Coverage 86.11% 86.13% +0.01%
==========================================
Files 115 115
Lines 45723 45734 +11
==========================================
+ Hits 39376 39392 +16
+ Misses 6347 6342 -5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
This relates to...
Fixes #2791
Rationale
With MockAgent,
pipeline()hangs if the request body is bigger than the highWaterMark. The mock only reads a stream body when the handler hasonBodySent/onRequestSent, and the pipeline handler has neither, so the writable side waits on backpressure forever. Against a real server the body gets consumed, so it works there.Changes
Features
N/A
Bug Fixes
readableDidRead === false). Bodies already read by a reply callback oronBodySentare left alone.mockAgent.pipeline(), and an unread body that errors after the reply.One thing to note: if a reply callback keeps a reference to
opts.bodyand only reads it after the response has ended, it'll now find it drained. I don't think that's a real use case, but happy to narrow this down if you'd prefer.Breaking Changes and Deprecations
N/A
Status