fix(PortProxy): Improved connection cleanup process with added asynchronous delays

This commit is contained in:
Philipp Kunz 2025-02-27 15:05:38 +00:00
parent 6ca14edb38
commit ef707a5870
3 changed files with 11 additions and 2 deletions

View File

@ -1,5 +1,10 @@
# Changelog # Changelog
## 2025-02-27 - 3.16.5 - fix(PortProxy)
Improved connection cleanup process with added asynchronous delays
- Connection cleanup now includes asynchronous delays for reliable order of operations.
## 2025-02-27 - 3.16.4 - fix(PortProxy) ## 2025-02-27 - 3.16.4 - fix(PortProxy)
Fix and enhance port proxy handling Fix and enhance port proxy handling

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartproxy', name: '@push.rocks/smartproxy',
version: '3.16.4', version: '3.16.5',
description: 'A robust and versatile proxy package designed to handle high workloads, offering features like SSL redirection, port proxying, WebSocket support, and customizable routing and authentication.' description: 'A robust and versatile proxy package designed to handle high workloads, offering features like SSL redirection, port proxying, WebSocket support, and customizable routing and authentication.'
} }

View File

@ -140,14 +140,18 @@ export class PortProxy {
let outgoingTerminationReason: string | null = null; let outgoingTerminationReason: string | null = null;
// Ensure cleanup happens only once for the entire connection record. // Ensure cleanup happens only once for the entire connection record.
const cleanupOnce = () => { const cleanupOnce = async () => {
if (!connectionRecord.connectionClosed) { if (!connectionRecord.connectionClosed) {
connectionRecord.connectionClosed = true; connectionRecord.connectionClosed = true;
await plugins.smartdelay.delayFor(0);
if (connectionRecord.cleanupTimer) { if (connectionRecord.cleanupTimer) {
clearTimeout(connectionRecord.cleanupTimer); clearTimeout(connectionRecord.cleanupTimer);
} }
await plugins.smartdelay.delayFor(0);
if (!socket.destroyed) socket.destroy(); if (!socket.destroyed) socket.destroy();
await plugins.smartdelay.delayFor(0);
if (connectionRecord.outgoing && !connectionRecord.outgoing.destroyed) connectionRecord.outgoing.destroy(); if (connectionRecord.outgoing && !connectionRecord.outgoing.destroyed) connectionRecord.outgoing.destroy();
await plugins.smartdelay.delayFor(0);
this.connectionRecords.delete(connectionRecord); this.connectionRecords.delete(connectionRecord);
console.log(`Connection from ${remoteIP} terminated. Active connections: ${this.connectionRecords.size}`); console.log(`Connection from ${remoteIP} terminated. Active connections: ${this.connectionRecords.size}`);
} }