Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ClientRequest): prevent req.write() callbacks from being called twice on passthrough #685

Merged
merged 2 commits into from
Dec 1, 2024

Conversation

kettanaito
Copy link
Member

@kettanaito kettanaito commented Dec 1, 2024

Changes

During the flushWriteBuffer(), set the invoked callback on the write args to undefined so it doesn't get called again (twice) during passthrough of requests that call request.end() within the request.write() callback. The issue is only reproducible in that scenario and doesn't happen on sequential write/end calls.

* if `request.end()` was called within `request.write()`.
* @see https://github.com/mswjs/interceptors/issues/684
*/
writeCall[2] = undefined
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to go with the replacement approach because it's simpler than introducing an internal symbol.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

@kettanaito kettanaito changed the title fix(ClientRequest): exhaust write buffer callbacks fix(ClientRequest): prevent req.write() callbacks from being called twice on passthrough Dec 1, 2024
@kettanaito kettanaito requested a review from mikicho December 1, 2024 14:21
@mikicho
Copy link
Contributor

mikicho commented Dec 1, 2024

Thanks! nock tests pass. 🎉

so it doesn't get called again (twice) during passthrough

I forgot that interceptors passthrough the request by default 🤦

* if `request.end()` was called within `request.write()`.
* @see https://github.com/mswjs/interceptors/issues/684
*/
writeCall[2] = undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

@kettanaito kettanaito merged commit e3c2a0b into main Dec 1, 2024
2 checks passed
@kettanaito kettanaito deleted the fix/request-write-twice branch December 1, 2024 19:54
@kettanaito
Copy link
Member Author

Thanks for looking at this one! 🎉

@kettanaito
Copy link
Member Author

Released: v0.37.2 🎉

This has been released in v0.37.2!

Make sure to always update to the latest version (npm i @mswjs/interceptors@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

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.

ClientRequest: write callback get called twice (FormData are broken)
2 participants