Skip to content

fix(fetch): don't enqueue the body twice when close is delayed - #6094

Open
cestercian wants to merge 1 commit into
nodejs:mainfrom
cestercian:cursor/fix-extractbody-double-enqueue-f443
Open

cestercian wants to merge 1 commit into
nodejs:mainfrom
cestercian:cursor/fix-extractbody-double-enqueue-f443

Conversation

@cestercian

Copy link
Copy Markdown

Fixes #6092

For string and byte bodies, pull() enqueues the whole thing and then closes the stream from a queueMicrotask (because of nodejs/node#39758). If pull() runs again before that microtask, the same bytes got enqueued again, so the body could come out duplicated.

This tracks whether the bytes were already enqueued and skips the enqueue (and the extra close) on later pulls. Async iterable bodies aren't touched.

Added test/fetch/issue-6092.js, which delays queueMicrotask with setImmediate and reads a string body and a Uint8Array body. It gets 5 chunks before the change and 1 after.

npm run lint passes, and the fetch tests pass locally except test/fetch/cookies.js (HTTP/2 TLS handshake), which fails the same way on main for me.

A byte-sequence body is closed from a microtask. If pull runs again
before that close, the same bytes were enqueued once more.

Signed-off-by: Cestercian <yashafaid@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extractBody: a byte-sequence body is enqueued again on each pull until the stream closes (since 8.12.0)

1 participant