fix: address PR review feedback - remove duplicate signal handlers and ensure PID cleanup

Addresses code review feedback from PR #489:

1. Moved PID file cleanup into shutdown() method to ensure it's always
   cleaned up regardless of how shutdown is triggered
2. Removed duplicate signal handlers in main() function that were
   redundant with the handlers in start() method

This eliminates the race condition where both sets of handlers could
trigger, and ensures consistent PID file cleanup behavior.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Alex Newman
2025-12-29 16:10:19 -05:00
parent 5bd8181db9
commit 9eedbd4fbd
2 changed files with 49 additions and 60 deletions
File diff suppressed because one or more lines are too long
+3 -14
View File
@@ -857,6 +857,9 @@ export class WorkerService {
async shutdown(): Promise<void> {
logger.info('SYSTEM', 'Shutdown initiated');
// Clean up PID file on shutdown
removePidFile();
// STEP 1: Enumerate all child processes BEFORE we start closing things
const childPids = await this.getChildProcesses(process.pid);
logger.info('SYSTEM', 'Found child processes', { count: childPids.length, pids: childPids });
@@ -1181,20 +1184,6 @@ async function main() {
// Run server directly
const worker = new WorkerService();
process.on('SIGTERM', async () => {
logger.info('SYSTEM', 'Received SIGTERM');
await worker.shutdown();
removePidFile();
process.exit(0);
});
process.on('SIGINT', async () => {
logger.info('SYSTEM', 'Received SIGINT');
await worker.shutdown();
removePidFile();
process.exit(0);
});
worker.start().catch((error) => {
logger.failure('SYSTEM', 'Worker failed to start', {}, error as Error);
removePidFile();