From dd7e9e8416172f1e8a67f3ac476d81a741f3725b Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Tue, 2 Feb 2021 21:59:24 +0000 Subject: [PATCH] fix(core): update --- ts/smartproxy.portproxy.ts | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/ts/smartproxy.portproxy.ts b/ts/smartproxy.portproxy.ts index 16cbe17..285d31e 100644 --- a/ts/smartproxy.portproxy.ts +++ b/ts/smartproxy.portproxy.ts @@ -18,6 +18,14 @@ const portProxyCalls = { response.end(); }); httpServer.listen(7999); + const cleanUpSockets = (from: plugins.net.Socket, to: plugins.net.Socket) => { + from.end(); + to.end(); + from.removeAllListeners(); + to.removeEventListener(); + from.unpipe(); + to.unpipe(); + } netServer = net .createServer((from) => { const to = net.createConnection({ @@ -27,14 +35,29 @@ const portProxyCalls = { from.pipe(to); to.pipe(from); from.on('error', () => { - from.end(), to.end(); + cleanUpSockets(from, to); }); to.on('error', () => { - from.end(), to.end(); + cleanUpSockets(from, to); }); from.on('close', () => { - to.end(); + cleanUpSockets(from, to); }); + to.on('close', () => { + cleanUpSockets(from, to); + }); + from.on('timeout', () => { + cleanUpSockets(from, to); + }); + to.on('timeout', () => { + cleanUpSockets(from, to); + }); + from.on('end', () => { + cleanUpSockets(from, to); + }) + to.on('end', () => { + cleanUpSockets(from, to); + }) }) .listen(portArg); console.log(`PortProxy -> OK: Now listening on port ${portArg}`);