Listen to error events on sockets

This commit is contained in:
Sander Declerck 2025-10-10 13:55:39 +02:00
parent 7603a29182
commit a377fd6caa
No known key found for this signature in database
2 changed files with 12 additions and 0 deletions

View file

@ -5,6 +5,12 @@ import { HttpsProxyAgent } from "https-proxy-agent";
export function mitmConnect(req, clientSocket, isAllowed) {
const { hostname } = new URL(`http://${req.url}`);
clientSocket.on("error", () => {
// NO-OP
// This can happen if the client TCP socket sends RST instead of FIN.
// Not subscribing to 'close' event will cause node to throw and crash.
});
const server = createHttpsServer(hostname, isAllowed);
// Establish the connection