fix(core): improve shutdown cleanup, socket/stream robustness, and memory/cache handling

This commit is contained in:
2026-03-01 00:44:01 +00:00
parent 59a3f7978e
commit 74ad5cec90
13 changed files with 150 additions and 59 deletions

View File

@@ -111,6 +111,15 @@ export class MetricsManager {
this.securityMetrics.lastResetDate = currentDate;
}
// Prune old query timestamps (keep last 5 minutes)
const fiveMinutesAgo = Date.now() - 300000;
const idx = this.dnsMetrics.queryTimestamps.findIndex(ts => ts >= fiveMinutesAgo);
if (idx > 0) {
this.dnsMetrics.queryTimestamps = this.dnsMetrics.queryTimestamps.slice(idx);
} else if (idx === -1) {
this.dnsMetrics.queryTimestamps = [];
}
// Prune old time-series buckets every minute (don't wait for lazy query)
this.pruneOldBuckets();
}, 60000); // Check every minute
@@ -427,13 +436,9 @@ export class MetricsManager {
this.dnsMetrics.cacheMisses++;
}
// Track query timestamp
// Track query timestamp (pruning moved to resetInterval to avoid O(n) per query)
this.dnsMetrics.queryTimestamps.push(Date.now());
// Keep only timestamps from last 5 minutes
const fiveMinutesAgo = Date.now() - 300000;
this.dnsMetrics.queryTimestamps = this.dnsMetrics.queryTimestamps.filter(ts => ts >= fiveMinutesAgo);
// Track response time if provided
if (responseTimeMs) {
this.dnsMetrics.responseTimes.push(responseTimeMs);