mswjs / interceptors

Low-level network interception library.
https://npm.im/@mswjs/interceptors
MIT License
539 stars 123 forks source link

Support reusing the same Socket for multiple requests #594

Closed kettanaito closed 1 month ago

kettanaito commented 3 months ago

In theory, you can reuse the same Socket instance for multiple HTTP requests. There's a bunch of Socket pools in the Agent and the agent decides which socket to use at which time.

That being said, I don't believe we allow our MockHttpSocket to be used that way. For once, each Socket instance has its own HTTP request/response parser instances, and I'm not sure if reusing sockets implies parallel reusing or sequential. I bet on sequential but who knows.

The tests for this are in works here: https://github.com/mswjs/interceptors/pull/560. I wasn't able to even recreate a raw, unmocked scenario of how you can reuse a socket like that. There's a solid chance I misread the Node.js docs and sockets cannot be used that way. No matter way I do with a keepalive socket/request, it never gets reused.

kettanaito commented 1 month ago

I will close this as not an issue until proven otherwise. If you experience an issue related to reusing the same Socket instance across multiple requests, please comment below with a reproduction repository attached. Thanks.