moll / node-mitm

Intercept and mock outgoing Node.js network TCP connections and HTTP requests for testing. Intercepts and gives you a Net.Socket, Http.IncomingMessage and Http.ServerResponse to test and respond with. Super useful when testing code that hits remote servers.
Other
641 stars 48 forks source link

Added a failing keep-alive test #36

Closed papandreou closed 3 months ago

papandreou commented 8 years ago

I ran into a problem in unexpected-mitm-land where a test would break when keep-alive is active. When connecting to the same host:port as a previous test had also touched, the socket from the Mitm instance would be retrieved from the freeSockets object of the Agent instance, causing breakage (res.connection being undefined).

Ended up adding a workaround, but it seems reasonable that this should be fixed in mitm.

I haven't been able to pinpoint exactly how res.connection ended up undefined, but I managed to create the enclosed mitm test that shows that the same socket is being handed out even though the Mitm instance has been destroyed and recreated in the meantime. If we can agree that it shouldn't do that, we can start from there :)

I'm assuming that this problem is also the cause of https://github.com/moll/node-mitm/pull/31