From 4cb9beb2003539361fc144d9a60206230a5008ce Mon Sep 17 00:00:00 2001 From: Adam A Date: Thu, 21 Nov 2024 15:56:37 +0100 Subject: [PATCH] fix closing of connections --- control_out_proxy.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/control_out_proxy.js b/control_out_proxy.js index 3840734..9d21ca9 100755 --- a/control_out_proxy.js +++ b/control_out_proxy.js @@ -47,23 +47,23 @@ async function run (localHost, controlPort, proxyConfig) { if (canConnect) { console.log('🟠 Disabling new connections') canConnect = false - if (connectionsJustClosed > 0) { - console.log('Closing', connectionsJustClosed, 'open connection(s)') - for (const connection of connections) { - try { - connection.close() - console.log('Closed:', connection.localAddr, '<->', connection.remoteAddr) - connectionsJustClosed++ - } catch (e) { - if (e.name === 'BadResource') { - console.log('Already closed:', connection.localAddr, '<->', connection.remoteAddr) - connectionsAlreadyClosed++ - } else { - throw e - } + } + if (connections.size > 0) { + console.log('Closing', connectionsJustClosed, 'open connection(s)') + for (const connection of connections) { + try { + connection.close() + console.log('Closed:', connection.localAddr, '<->', connection.remoteAddr) + connectionsJustClosed++ + } catch (e) { + if (e.name === 'BadResource') { + console.log('Already closed:', connection.localAddr, '<->', connection.remoteAddr) + connectionsAlreadyClosed++ + } else { + throw e } - connections.delete(connection) } + connections.delete(connection) } } return respond(200, {