Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
fix(serve): only restart workers if their exit was uninentional (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggilmore authored Jun 6, 2018
1 parent faa787c commit 7bda4cb
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,17 @@ export function serve(
logger.log(`Worker ${worker.id} (PID ${worker.process.pid}) online`)
})
cluster.on('exit', (worker, code, signal) => {
logger.error(
`Worker ${worker.id} (PID ${
worker.process.pid
}) exited from signal ${signal} with code ${code}, restarting`
)
cluster.fork()
const baseLogMessage = `Worker ${worker.id} (PID ${
worker.process.pid
}) exited from signal ${signal} with code ${code}`

if (!worker.exitedAfterDisconnect) {
logger.error(`${baseLogMessage}, restarting`)
cluster.fork()
return
}

logger.info(`${baseLogMessage}, not restarting since exit was voluntary`)
})
for (let i = 0; i < options.clusterSize; ++i) {
cluster.fork()
Expand Down

0 comments on commit 7bda4cb

Please sign in to comment.