-
-
Notifications
You must be signed in to change notification settings - Fork 133
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 stacked proxies when intercepting node http(s) requests #697
base: main
Are you sure you want to change the base?
Conversation
…ing node http(s) requests It was possible to end up with the http.request (etc) proxies wrapping existing proxies, which can cause odd behaviour.
Add logging so we know when we update an existing proxy and fix some linting (remove semicolons)
How does the code pass the check for an already applied interceptor? It seems like this is the problem we need to solve. |
I'm doing some more digging, but the core problem/discrepancy seems to come from this scenario:
How we end up with |
@sam-super, I think Jest contributes to this by creating a test sandbox. It may wipe out |
@mikicho yup just tested it and |
So MSW's attempt to use Because the Ideally maybe jest should reset the native-module cache between each test to remove any state that is attached (i.e. the interceptor proxy). Not sure how feasible it will be though. From my testing jest's own I know this PR isn't ideal, but i think preventing the stacking of proxies is probably still a good thing, and if MSW errors on detecting the proxy, it might break a lot of code that uses MSW in node/jest, so updating the proxy to the latest seems the least-bad way IMO. |
It was possible to end up with the http(s).request/get proxies wrapping existing proxies, which can cause odd behaviour:
nock/nock#2802
This PR attempts to fix the issue by only creating a proxy once, and just updating the callbacks the proxy uses when it's called a second time. it's not idea (since it could cause confusion with the previous instance, which will now no longer be invoked), but it seems like a preferable scenario.
instead we could error when an existing proxy is detected, but it seems like it would cause a lot of errors in practice (due to nodes module loader cache being inconsistent).