Commit e36b085c authored by smartcontracts's avatar smartcontracts Committed by GitHub

feat(cmn): hard stop on multiple exit signals (#2378)

Adds a new feature to BaseServiceV2 to have a service exit immediately
when 3 exit signals are received. Useful when the main loop would take a
long time to exit but you want the service to exit immediately.
Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 7a179003
---
'@eth-optimism/common-ts': patch
---
Adds hard stop to BaseServiceV2 when multiple exit signals are received
......@@ -247,11 +247,26 @@ export abstract class BaseServiceV2<
this.logger = new Logger({ name: params.name })
// Gracefully handle stop signals.
const maxSignalCount = 3
let currSignalCount = 0
const stop = async (signal: string) => {
this.logger.info(`stopping service with signal`, { signal })
await this.stop()
process.exit(0)
// Allow exiting fast if more signals are received.
currSignalCount++
if (currSignalCount === 1) {
this.logger.info(`stopping service with signal`, { signal })
await this.stop()
process.exit(0)
} else if (currSignalCount >= maxSignalCount) {
this.logger.info(`performing hard stop`)
process.exit(0)
} else {
this.logger.info(
`send ${maxSignalCount - currSignalCount} more signal(s) to hard stop`
)
}
}
// Handle stop signals.
process.on('SIGTERM', stop)
process.on('SIGINT', stop)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment