fix(PortProxy): Improved connection cleanup process with added asynchronous delays
This commit is contained in:
@ -140,14 +140,18 @@ export class PortProxy {
|
||||
let outgoingTerminationReason: string | null = null;
|
||||
|
||||
// Ensure cleanup happens only once for the entire connection record.
|
||||
const cleanupOnce = () => {
|
||||
const cleanupOnce = async () => {
|
||||
if (!connectionRecord.connectionClosed) {
|
||||
connectionRecord.connectionClosed = true;
|
||||
await plugins.smartdelay.delayFor(0);
|
||||
if (connectionRecord.cleanupTimer) {
|
||||
clearTimeout(connectionRecord.cleanupTimer);
|
||||
}
|
||||
await plugins.smartdelay.delayFor(0);
|
||||
if (!socket.destroyed) socket.destroy();
|
||||
await plugins.smartdelay.delayFor(0);
|
||||
if (connectionRecord.outgoing && !connectionRecord.outgoing.destroyed) connectionRecord.outgoing.destroy();
|
||||
await plugins.smartdelay.delayFor(0);
|
||||
this.connectionRecords.delete(connectionRecord);
|
||||
console.log(`Connection from ${remoteIP} terminated. Active connections: ${this.connectionRecords.size}`);
|
||||
}
|
||||
|
Reference in New Issue
Block a user