fix(backport): apply body delay before the response end#2969
Merged
Conversation
This fixes a regression where `delayBody(N)` no longer makes a body look
slow to the caller. Read timeouts on the response stream are expected to
fire when N exceeds them, but in v14 the @mswjs/interceptors-based
pipeline drains the response body before delivering the response event.
Pausing the body source (the v13 mechanism) ended up delaying the
*whole* response — response, data, and end events all moved to
`+delayBodyInMs`, indistinguishable from a slow connection.
Two coordinated pieces fix it:
1. `lib/playback_interceptor.js`: drop the pause/resume mechanism and
gate only the end-of-response push (`response.push(null)`) on
`delayBodyInMs`. Schedule that gate inside `respond()` so
`delay({ head, body })` continues to compound — head defers the
response event, body then defers the end signal by an additional
`body` ms. Reply callbacks like `replyWithFile` hand back an
explicitly-paused `fs.createReadStream`, so call
`bodyAsStream.resume()` to ensure the body flows.
2. `tests/got/test_delay.js`: the two tests that asserted timing on the
first `data` event are updated to assert on the `end` event,
matching the new (and intended) semantics.
Refs: nock#2867
Fixes: nock#2863
mikicho
approved these changes
Apr 30, 2026
Member
|
Thanks! |
|
🎉 This PR is included in version 14.0.14 🎉 The release is available on: Your semantic-release 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.
This fixes a regression where
delayBody(N)no longer makes a body look slow to the caller. Read timeouts on the response stream are expected to fire when N exceeds them, but in v14 the @mswjs/interceptors-based pipeline drains the response body before delivering the response event. Pausing the body source (the v13 mechanism) ended up delaying the whole response — response, data, and end events all moved to+delayBodyInMs, indistinguishable from a slow connection.Two coordinated pieces fix it:
lib/playback_interceptor.js: drop the pause/resume mechanism and gate only the end-of-response push (response.push(null)) ondelayBodyInMs. Schedule that gate insiderespond()sodelay({ head, body })continues to compound — head defers the response event, body then defers the end signal by an additionalbodyms. Reply callbacks likereplyWithFilehand back an explicitly-pausedfs.createReadStream, so callbodyAsStream.resume()to ensure the body flows.tests/got/test_delay.js: the two tests that asserted timing on the firstdataevent are updated to assert on theendevent, matching the new (and intended) semantics.Refs: #2867
Fixes: #2863