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

HTTP requests made via Stripe SDK hang #2785

Closed
1 of 2 tasks
kanadgupta opened this issue Sep 24, 2024 · 9 comments
Closed
1 of 2 tasks

HTTP requests made via Stripe SDK hang #2785

kanadgupta opened this issue Sep 24, 2024 · 9 comments
Labels

Comments

@kanadgupta
Copy link

Please avoid duplicates

Reproducible test case

https://github.com/kanadgupta/nock-beta-stripe-sdk

Nock Version

nock@14.0.0-beta.14

Node Version

v20.16.0

TypeScript Version

No response

What happened?

HTTP requests using Stripe's Node.js SDK will hang indefinitely if nock is loaded at all (whether or not there is an interceptor defined for the Stripe request).

I am not well-versed in nock nor in the Stripe SDK but I can confirm that this issue was not present in nock@14.0.0-beta.7 nor in nock@latest (e.g., before mswjs/interceptors was introduced).

Would you be interested in contributing a fix?

  • yes
@mikicho
Copy link
Contributor

mikicho commented Sep 25, 2024

Can you please remove the stripe dependency from your example?

@kanadgupta
Copy link
Author

@mikicho the stripe dependency is a critical part of the issue so I'm not sure what removing it would accomplish. To clarify, the issue is with how nock is hanging on HTTP requests that are made by the stripe library.

I did a little bit of digging and I found this PR that might be related: stripe/stripe-node#1854 (which, funnily enough, is an effort to get the stripe library to play nicely with MSW 😅)

@mikicho
Copy link
Contributor

mikicho commented Sep 25, 2024

Oh.. this is probably the problem. When you import http This way, we can't patch the http module. please change it in stripe module:
More info/Similar question: #2778

@mikicho mikicho closed this as completed Sep 25, 2024
@kanadgupta
Copy link
Author

@mikicho I considered opening up an issue the stripe repo, but I ended up flagging it here because the stripe library was working as expected in nock@14.0.0-beta.7 and in nock@latest. The issue started cropping up in nock@14.0.0-beta.8.

Plus it appears that the Stripe team has done some work on this front:
stripe/stripe-node#1844
stripe/stripe-node#1854
stripe/stripe-node#1866

Happy to raise an issue there if you are sure it's an issue with the Stripe SDK. Thanks for all your work on this, excited for a proper v14 release!

@mikicho
Copy link
Contributor

mikicho commented Sep 26, 2024

Thanks! Can you please provide a more straightforward example without stripe? I don't want to debug the stripe package.

@mikicho mikicho reopened this Sep 26, 2024
@sonntag-philipp
Copy link

This should be the exact location where the issue happens: https://github.com/stripe/stripe-node/blob/768206df1b9d025853d5e34e6046beb502effdd9/src/net/NodeHttpClient.ts#L83

Maybe this helps already.

@mikicho
Copy link
Contributor

mikicho commented Oct 19, 2024

@sonntag-philipp Yes.. this is a limitation of our current interception implementation. We can't req.end inside the connect event.
As a workaround, you can explicitly call req.flushHeaders to make sure nock gets the request.

mswjs/interceptors#646

@kanadgupta
Copy link
Author

I found that the workaround mentioned in this comment (thanks @jeyj0!) solves my problem. I've filed a bug report in the stripe-node repo: stripe/stripe-node#2211

@mikicho I'll keep this open and let you decide how to triage this.

@mikicho
Copy link
Contributor

mikicho commented Oct 21, 2024

🎉

I'll close this one; we track this issue on the msw/interceptors repo.

@mikicho mikicho closed this as completed Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants