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:
@ -45,7 +45,7 @@
|
|||||||
"@push.rocks/smartnetwork": "^4.0.2",
|
"@push.rocks/smartnetwork": "^4.0.2",
|
||||||
"@push.rocks/smartpath": "^5.0.5",
|
"@push.rocks/smartpath": "^5.0.5",
|
||||||
"@push.rocks/smartpromise": "^4.0.3",
|
"@push.rocks/smartpromise": "^4.0.3",
|
||||||
"@push.rocks/smartproxy": "^19.6.0",
|
"@push.rocks/smartproxy": "^19.6.1",
|
||||||
"@push.rocks/smartrequest": "^2.1.0",
|
"@push.rocks/smartrequest": "^2.1.0",
|
||||||
"@push.rocks/smartrule": "^2.0.1",
|
"@push.rocks/smartrule": "^2.0.1",
|
||||||
"@push.rocks/smartrx": "^3.0.10",
|
"@push.rocks/smartrx": "^3.0.10",
|
||||||
|
14
pnpm-lock.yaml
generated
14
pnpm-lock.yaml
generated
@ -72,8 +72,8 @@ importers:
|
|||||||
specifier: ^4.0.3
|
specifier: ^4.0.3
|
||||||
version: 4.2.3
|
version: 4.2.3
|
||||||
'@push.rocks/smartproxy':
|
'@push.rocks/smartproxy':
|
||||||
specifier: ^19.6.0
|
specifier: ^19.6.1
|
||||||
version: 19.6.0(@aws-sdk/credential-providers@3.817.0)(socks@2.8.4)
|
version: 19.6.1(@aws-sdk/credential-providers@3.817.0)(socks@2.8.4)
|
||||||
'@push.rocks/smartrequest':
|
'@push.rocks/smartrequest':
|
||||||
specifier: ^2.1.0
|
specifier: ^2.1.0
|
||||||
version: 2.1.0
|
version: 2.1.0
|
||||||
@ -1062,8 +1062,8 @@ packages:
|
|||||||
'@push.rocks/smartpromise@4.2.3':
|
'@push.rocks/smartpromise@4.2.3':
|
||||||
resolution: {integrity: sha512-Ycg/TJR+tMt+S3wSFurOpEoW6nXv12QBtKXgBcjMZ4RsdO28geN46U09osPn9N9WuwQy1PkmTV5J/V4F9U8qEw==}
|
resolution: {integrity: sha512-Ycg/TJR+tMt+S3wSFurOpEoW6nXv12QBtKXgBcjMZ4RsdO28geN46U09osPn9N9WuwQy1PkmTV5J/V4F9U8qEw==}
|
||||||
|
|
||||||
'@push.rocks/smartproxy@19.6.0':
|
'@push.rocks/smartproxy@19.6.1':
|
||||||
resolution: {integrity: sha512-qMayuTkKpgQM14Z2cksjG8NmF6KLogcmXQIKUSFx/W7kKoGSkZ+/kYbnngDpc87n86nathr0p2H2euUt0lHfRQ==}
|
resolution: {integrity: sha512-CkztOqRR1i0icOPad5TlzjrNAXvr/L3BMjlo+fhp3c/dPuXV9Z/isOECz0Flk0A3anKIgCqC9pGNzdNdssLUsQ==}
|
||||||
|
|
||||||
'@push.rocks/smartpuppeteer@2.0.5':
|
'@push.rocks/smartpuppeteer@2.0.5':
|
||||||
resolution: {integrity: sha512-yK/qSeWVHIGWRp3c8S5tfdGP6WCKllZC4DR8d8CQlEjszOSBmHtlTdyyqOMBZ/BA4kd+eU5f3A1r4K2tGYty1g==}
|
resolution: {integrity: sha512-yK/qSeWVHIGWRp3c8S5tfdGP6WCKllZC4DR8d8CQlEjszOSBmHtlTdyyqOMBZ/BA4kd+eU5f3A1r4K2tGYty1g==}
|
||||||
@ -5440,10 +5440,8 @@ snapshots:
|
|||||||
'@push.rocks/taskbuffer': 3.1.7
|
'@push.rocks/taskbuffer': 3.1.7
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- '@nuxt/kit'
|
- '@nuxt/kit'
|
||||||
- bufferutil
|
|
||||||
- react
|
- react
|
||||||
- supports-color
|
- supports-color
|
||||||
- utf-8-validate
|
|
||||||
- vue
|
- vue
|
||||||
|
|
||||||
'@hapi/hoek@9.3.0': {}
|
'@hapi/hoek@9.3.0': {}
|
||||||
@ -5786,6 +5784,7 @@ snapshots:
|
|||||||
- '@mongodb-js/zstd'
|
- '@mongodb-js/zstd'
|
||||||
- '@nuxt/kit'
|
- '@nuxt/kit'
|
||||||
- aws-crt
|
- aws-crt
|
||||||
|
- bufferutil
|
||||||
- encoding
|
- encoding
|
||||||
- gcp-metadata
|
- gcp-metadata
|
||||||
- kerberos
|
- kerberos
|
||||||
@ -5794,6 +5793,7 @@ snapshots:
|
|||||||
- snappy
|
- snappy
|
||||||
- socks
|
- socks
|
||||||
- supports-color
|
- supports-color
|
||||||
|
- utf-8-validate
|
||||||
- vue
|
- vue
|
||||||
|
|
||||||
'@push.rocks/smartarchive@3.0.8':
|
'@push.rocks/smartarchive@3.0.8':
|
||||||
@ -6223,7 +6223,7 @@ snapshots:
|
|||||||
|
|
||||||
'@push.rocks/smartpromise@4.2.3': {}
|
'@push.rocks/smartpromise@4.2.3': {}
|
||||||
|
|
||||||
'@push.rocks/smartproxy@19.6.0(@aws-sdk/credential-providers@3.817.0)(socks@2.8.4)':
|
'@push.rocks/smartproxy@19.6.1(@aws-sdk/credential-providers@3.817.0)(socks@2.8.4)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@push.rocks/lik': 6.2.2
|
'@push.rocks/lik': 6.2.2
|
||||||
'@push.rocks/smartacme': 8.0.0(@aws-sdk/credential-providers@3.817.0)(socks@2.8.4)
|
'@push.rocks/smartacme': 8.0.0(@aws-sdk/credential-providers@3.817.0)(socks@2.8.4)
|
||||||
|
@ -221,12 +221,13 @@ export class MultiModeDeliverySystem extends EventEmitter {
|
|||||||
const checkInterval = setInterval(() => {
|
const checkInterval = setInterval(() => {
|
||||||
if (this.activeDeliveries.size === 0) {
|
if (this.activeDeliveries.size === 0) {
|
||||||
clearInterval(checkInterval);
|
clearInterval(checkInterval);
|
||||||
|
clearTimeout(forceTimeout);
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
// Force resolve after 30 seconds
|
// Force resolve after 30 seconds
|
||||||
setTimeout(() => {
|
const forceTimeout = setTimeout(() => {
|
||||||
clearInterval(checkInterval);
|
clearInterval(checkInterval);
|
||||||
resolve();
|
resolve();
|
||||||
}, 30000);
|
}, 30000);
|
||||||
|
@ -247,11 +247,23 @@ export class ConnectionManager implements IConnectionManager {
|
|||||||
|
|
||||||
// 2. Check for destroyed sockets in active connections
|
// 2. Check for destroyed sockets in active connections
|
||||||
let destroyedSocketsCount = 0;
|
let destroyedSocketsCount = 0;
|
||||||
|
const socketsToRemove: Array<plugins.net.Socket | plugins.tls.TLSSocket> = [];
|
||||||
|
|
||||||
for (const socket of this.activeConnections) {
|
for (const socket of this.activeConnections) {
|
||||||
if (socket.destroyed) {
|
if (socket.destroyed) {
|
||||||
destroyedSocketsCount++;
|
destroyedSocketsCount++;
|
||||||
// This should not happen - remove destroyed sockets from tracking
|
socketsToRemove.push(socket);
|
||||||
this.activeConnections.delete(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)}`);
|
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
|
// Set up event handlers
|
||||||
this.setupSocketEventHandlers(socket);
|
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)}`);
|
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
|
// Set up event handlers
|
||||||
this.setupSocketEventHandlers(socket);
|
this.setupSocketEventHandlers(socket);
|
||||||
|
|
||||||
@ -763,6 +769,9 @@ export class ConnectionManager implements IConnectionManager {
|
|||||||
clearTimeout(session.dataTimeoutId);
|
clearTimeout(session.dataTimeoutId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove all event listeners to prevent memory leaks
|
||||||
|
socket.removeAllListeners();
|
||||||
|
|
||||||
// Log connection close with session details if available
|
// Log connection close with session details if available
|
||||||
adaptiveLogger.logConnection(socket, 'close', session);
|
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
|
// Ensure socket is removed from active connections even if an error occurs
|
||||||
this.activeConnections.delete(socket);
|
this.activeConnections.delete(socket);
|
||||||
|
|
||||||
|
// Always try to remove all listeners even on error
|
||||||
|
try {
|
||||||
|
socket.removeAllListeners();
|
||||||
|
} catch {
|
||||||
|
// Ignore errors from removeAllListeners
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,10 @@ export class MetricsManager {
|
|||||||
private logger: plugins.smartlog.Smartlog;
|
private logger: plugins.smartlog.Smartlog;
|
||||||
private smartMetrics: plugins.smartmetrics.SmartMetrics;
|
private smartMetrics: plugins.smartmetrics.SmartMetrics;
|
||||||
private dcRouter: DcRouter;
|
private dcRouter: DcRouter;
|
||||||
|
private resetInterval?: NodeJS.Timeout;
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
private readonly MAX_TOP_DOMAINS = 1000; // Limit topDomains Map size
|
||||||
|
|
||||||
// Track email-specific metrics
|
// Track email-specific metrics
|
||||||
private emailMetrics = {
|
private emailMetrics = {
|
||||||
@ -54,7 +58,7 @@ export class MetricsManager {
|
|||||||
this.smartMetrics.start();
|
this.smartMetrics.start();
|
||||||
|
|
||||||
// Reset daily counters at midnight
|
// Reset daily counters at midnight
|
||||||
setInterval(() => {
|
this.resetInterval = setInterval(() => {
|
||||||
const currentDate = new Date().toDateString();
|
const currentDate = new Date().toDateString();
|
||||||
|
|
||||||
if (currentDate !== this.emailMetrics.lastResetDate) {
|
if (currentDate !== this.emailMetrics.lastResetDate) {
|
||||||
@ -88,6 +92,12 @@ export class MetricsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async stop(): Promise<void> {
|
public async stop(): Promise<void> {
|
||||||
|
// Clear the reset interval
|
||||||
|
if (this.resetInterval) {
|
||||||
|
clearInterval(this.resetInterval);
|
||||||
|
this.resetInterval = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
this.smartMetrics.stop();
|
this.smartMetrics.stop();
|
||||||
this.logger.log('info', 'MetricsManager stopped');
|
this.logger.log('info', 'MetricsManager stopped');
|
||||||
}
|
}
|
||||||
@ -232,9 +242,23 @@ export class MetricsManager {
|
|||||||
// Track query types
|
// Track query types
|
||||||
this.dnsMetrics.queryTypes[queryType] = (this.dnsMetrics.queryTypes[queryType] || 0) + 1;
|
this.dnsMetrics.queryTypes[queryType] = (this.dnsMetrics.queryTypes[queryType] || 0) + 1;
|
||||||
|
|
||||||
// Track top domains
|
// Track top domains with size limit
|
||||||
const currentCount = this.dnsMetrics.topDomains.get(domain) || 0;
|
const currentCount = this.dnsMetrics.topDomains.get(domain) || 0;
|
||||||
this.dnsMetrics.topDomains.set(domain, currentCount + 1);
|
this.dnsMetrics.topDomains.set(domain, currentCount + 1);
|
||||||
|
|
||||||
|
// If we've exceeded the limit, remove the least accessed domains
|
||||||
|
if (this.dnsMetrics.topDomains.size > this.MAX_TOP_DOMAINS) {
|
||||||
|
// Convert to array, sort by count, and keep only top domains
|
||||||
|
const sortedDomains = Array.from(this.dnsMetrics.topDomains.entries())
|
||||||
|
.sort((a, b) => b[1] - a[1])
|
||||||
|
.slice(0, Math.floor(this.MAX_TOP_DOMAINS * 0.8)); // Keep 80% to avoid frequent cleanup
|
||||||
|
|
||||||
|
// Clear and repopulate with top domains
|
||||||
|
this.dnsMetrics.topDomains.clear();
|
||||||
|
sortedDomains.forEach(([domain, count]) => {
|
||||||
|
this.dnsMetrics.topDomains.set(domain, count);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Security event tracking methods
|
// Security event tracking methods
|
||||||
|
Reference in New Issue
Block a user