Skip to content

Commit 6da16a4

Browse files
committed
fix(12-04): add process signal handlers to ResourceCache
- Clear existing interval before creating new one in enablePersistence - Register SIGTERM and SIGINT handlers for graceful shutdown - Ensures intervals are cleaned up on process exit - Prevents resource leaks in long-running processes
1 parent 0fb8ead commit 6da16a4

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/infrastructure/cache/ResourceCache.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,12 @@ export class ResourceCache {
488488
return;
489489
}
490490

491+
// Clear any existing interval first to prevent duplicates
492+
if (this.persistInterval) {
493+
clearInterval(this.persistInterval);
494+
this.persistInterval = undefined;
495+
}
496+
491497
this.persistence = new CachePersistence(cacheDirectory);
492498

493499
// Start periodic persistence
@@ -500,6 +506,15 @@ export class ResourceCache {
500506
}
501507
}, this.PERSIST_INTERVAL_MS);
502508

509+
// Register cleanup on process termination signals
510+
const cleanup = async () => {
511+
await this.shutdown();
512+
process.exit(0);
513+
};
514+
515+
process.once('SIGTERM', cleanup);
516+
process.once('SIGINT', cleanup);
517+
503518
process.stderr.write(
504519
`[ResourceCache] Persistence enabled (interval: ${this.PERSIST_INTERVAL_MS}ms)\n`
505520
);

0 commit comments

Comments
 (0)