* Start periodic cleanup of expired rate limit counters and cached configs * * Runs every 10 seconds to: * - Remove expired GCRA counters (where emptyAt <= now) * - Remove expired cached rate limit configs (where TTL expired) * - Remove expired cached bucket owners (where TTL expired) * * Thi
(log, options = {})
| 28 | * This prevents memory leaks from accumulating expired entries. |
| 29 | */ |
| 30 | function startCleanupJob(log, options = {}) { |
| 31 | if (cleanupTimer) { |
| 32 | log.warn('Rate limit cleanup job already running'); |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | log.info('Starting rate limit cleanup job', { |
| 37 | interval: rateLimitCleanupInterval, |
| 38 | }); |
| 39 | |
| 40 | cleanupTimer = setTimeout(() => cleanupJob(log, options), rateLimitCleanupInterval); |
| 41 | |
| 42 | // Prevent cleanup job from keeping process alive |
| 43 | // Skip unref() in test environment to work with sinon fake timers |
| 44 | if (!options.skipUnref) { |
| 45 | cleanupTimer.unref(); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Stop the periodic cleanup job |
no test coverage detected