node-http-mitm-proxy
node-http-mitm-proxy copied to clipboard
ProxyToServer connection timeout is not handled
Recently I bumped into the issue where my library (that uses this) was hanging after termination.
Debugging showed event loop was filled with TLSWrap
and socket calls which led me to connection timeouts and to these lines:
https://github.com/joeferner/node-http-mitm-proxy/blob/310a3bc8918b07b9c7dbdb345e358f8be2a74044/lib/proxy.ts#L1099-L1102
error
event does not include timeout
, so even after clients give up and close connection (ClientToProxy), these were left hanging.
Google led me to https://stackoverflow.com/a/55021202 and I've added
ctx.proxyToServerRequest.on("error", self._onError.bind(self, "PROXY_TO_SERVER_REQUEST_ERROR", ctx));
+ ctx.proxyToServerRequest.on("timeout", () => {ctx.proxyToServerRequest.destroy()});
The destroy()
is now triggering on timeout and then triggering the previously set error handler.
I haven't opened a PR with this as I'm not sure of its impact, leaving this up as an issue 😄
Calling destroy() on the http agents also destroys all open sockets and properly allows termination.
Currently doing this when calling Proxy.close()
same issue here