Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fair-cows-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/common-ts': patch
---

Adds hard stop to BaseServiceV2 when multiple exit signals are received
21 changes: 18 additions & 3 deletions packages/common-ts/src/base-service/base-service-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down