From 578d1ba2f7c62d4cfcfadd7e2ec46ffb54997e09 Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Fri, 6 Jun 2025 15:00:46 +0000 Subject: [PATCH] update --- .../smart-proxy/route-connection-handler.ts | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/ts/proxies/smart-proxy/route-connection-handler.ts b/ts/proxies/smart-proxy/route-connection-handler.ts index 74c3523..736528b 100644 --- a/ts/proxies/smart-proxy/route-connection-handler.ts +++ b/ts/proxies/smart-proxy/route-connection-handler.ts @@ -199,25 +199,29 @@ export class RouteConnectionHandler { setupSocketHandlers( underlyingSocket, (reason) => { - // Only cleanup if connection hasn't been fully established - // Check if outgoing connection exists and is connected - if (!record.outgoing || record.outgoing.readyState !== 'open') { - logger.log('debug', `Connection ${connectionId} closed during immediate routing: ${reason}`, { + // Always cleanup when incoming socket closes + // This prevents connection accumulation in proxy chains + logger.log('debug', `Connection ${connectionId} closed during immediate routing: ${reason}`, { + connectionId, + remoteIP: record.remoteIP, + reason, + hasOutgoing: !!record.outgoing, + outgoingState: record.outgoing?.readyState, + component: 'route-handler' + }); + + // If there's a pending or established outgoing connection, destroy it + if (record.outgoing && !record.outgoing.destroyed) { + logger.log('debug', `Destroying outgoing connection for ${connectionId}`, { connectionId, - remoteIP: record.remoteIP, - reason, - hasOutgoing: !!record.outgoing, - outgoingState: record.outgoing?.readyState, + outgoingState: record.outgoing.readyState, component: 'route-handler' }); - - // If there's a pending outgoing connection, destroy it - if (record.outgoing && !record.outgoing.destroyed) { - record.outgoing.destroy(); - } - - this.connectionManager.cleanupConnection(record, reason); + record.outgoing.destroy(); } + + // Always cleanup the connection record + this.connectionManager.cleanupConnection(record, reason); }, undefined, // Use default timeout handler 'immediate-route-client'