fix(core): improve shutdown cleanup, socket/stream robustness, and memory/cache handling
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user