fix: update @push.rocks/smartproxy to version 19.6.1 and improve socket management in ConnectionManager

feat: enhance MetricsManager with reset interval and top domains tracking
This commit is contained in:
2025-06-09 17:18:50 +00:00
parent 93995d5031
commit 02dd3c77b5
5 changed files with 60 additions and 19 deletions

View File

@ -247,11 +247,23 @@ export class ConnectionManager implements IConnectionManager {
// 2. Check for destroyed sockets in active connections
let destroyedSocketsCount = 0;
const socketsToRemove: Array<plugins.net.Socket | plugins.tls.TLSSocket> = [];
for (const socket of this.activeConnections) {
if (socket.destroyed) {
destroyedSocketsCount++;
// This should not happen - remove destroyed sockets from tracking
this.activeConnections.delete(socket);
socketsToRemove.push(socket);
}
}
// Remove destroyed sockets from tracking
for (const socket of socketsToRemove) {
this.activeConnections.delete(socket);
// Also ensure all listeners are removed
try {
socket.removeAllListeners();
} catch {
// Ignore errors from removeAllListeners
}
}
@ -341,9 +353,6 @@ export class ConnectionManager implements IConnectionManager {
SmtpLogger.debug(`Could not set socket buffer limits: ${error instanceof Error ? error.message : String(error)}`);
}
// Track this IP connection
this.trackIPConnection(remoteAddress);
// Set up event handlers
this.setupSocketEventHandlers(socket);
@ -498,9 +507,6 @@ export class ConnectionManager implements IConnectionManager {
SmtpLogger.debug(`Could not set socket buffer limits: ${error instanceof Error ? error.message : String(error)}`);
}
// Track this IP connection
this.trackIPConnection(remoteAddress);
// Set up event handlers
this.setupSocketEventHandlers(socket);
@ -763,6 +769,9 @@ export class ConnectionManager implements IConnectionManager {
clearTimeout(session.dataTimeoutId);
}
// Remove all event listeners to prevent memory leaks
socket.removeAllListeners();
// Log connection close with session details if available
adaptiveLogger.logConnection(socket, 'close', session);
@ -774,6 +783,13 @@ export class ConnectionManager implements IConnectionManager {
// Ensure socket is removed from active connections even if an error occurs
this.activeConnections.delete(socket);
// Always try to remove all listeners even on error
try {
socket.removeAllListeners();
} catch {
// Ignore errors from removeAllListeners
}
}
}