fix(MockHttpSocket): deadlock with clients that wait for secureConnect before writing anything
#745
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.
I opened mswjs/msw#2569 because I noticed some behavior with an HTTP client that waits for the
secureConnectevent to happen before writing anything, which causes a deadlock because the MSW interceptor waits forwritebefore firingsecureConnect.I've tried my best to also implement a solution given that I'm not an expert on how NodeJS sockets work by any means, but I wanted to at least try to be helpful. Any feedback on this PR is welcome. It seems to me like the code is a bit brittle. The implementation of the
oncemethod is the main thing that fixes that deadlock, but it caused other tests to fail so I went trying to handle each case one by one.I also confirmed that it fixes the issue in my reproduction repository. I tested it by building the client on my Mac and linking it like this:
Then I removed my
node_modulesand re-ranpnpm i, and sure enough when running the tests none of them time out anymore.One thing I would like is to add a test for this in this repo that reproduces the issue in the reproduction repo exactly. On my first iteration when I got the test in
test/modules/http/regressions/http-socket-secure-connect-passthrough.test.tsworking, all the tests in this repository were passing, but using the built package in my reproduction repository still didn't make it work. It was making that work that then caused all the regressions that I had to go fixing one by one. I'd love any tips on how I can make a test like that, I was thinking of copying howmswsets upClientRequestInterceptorbut it seemed like it would be very complicated to do.