fix(mail): add periodic cleanup timers and proper shutdown handling for bounce manager and delivery queue; avoid mutating maps during iteration and prune stale rate-limiter stats to prevent memory growth

This commit is contained in:
2026-03-02 14:06:47 +00:00
parent b465b01790
commit 8851d61466
5 changed files with 82 additions and 23 deletions

View File

@@ -231,7 +231,21 @@ export class UnifiedRateLimiter extends EventEmitter {
this.domainCounters.delete(key);
}
}
// Clean stale stats.byIp entries for IPs that no longer have active counters or blocks
for (const ip of Object.keys(this.stats.byIp)) {
if (!this.ipCounters.has(ip) && !(this.config.blocks && ip in this.config.blocks)) {
delete this.stats.byIp[ip];
}
}
// Clean stale stats.byPattern entries for patterns that no longer have active counters
for (const pattern of Object.keys(this.stats.byPattern)) {
if (!this.patternCounters.has(pattern)) {
delete this.stats.byPattern[pattern];
}
}
// Update statistics
this.updateStats();
}