Skip to content

Commit

Permalink
fixed crash loop
Browse files Browse the repository at this point in the history
  • Loading branch information
cmd committed Sep 26, 2023
1 parent 9449cc9 commit d739e3d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export class CoreDaemon extends EventEmitter {
readonly _opt : CoreConfig
readonly params : string[]

_proc ?: ChildProcess
_closing : boolean
_proc ?: ChildProcess

constructor (config ?: Partial<CoreConfig>) {
super()
Expand All @@ -41,6 +42,7 @@ export class CoreDaemon extends EventEmitter {
}

this._client = new CoreClient(opt)
this._closing = false

this.params = [
`-chain=${opt.network}`,
Expand All @@ -59,17 +61,23 @@ export class CoreDaemon extends EventEmitter {
this.params.push(`-rpcport=${opt.rpcport}`)
}
process.on('uncaughtException', async (err) => {
console.log('[core] Daemon caught an error, exiting...')
await this.shutdown()
if (!this._closing) {
console.log('[core] Daemon caught an error, exiting...')
await this.shutdown()
this._closing = true
}
if (throws) {
throw err
} else {
console.log(err.message)
}
})
process.on('unhandledRejection', async (reason) => {
console.log('[core] Daemon caught a promise rejection, exiting...')
await this.shutdown()
if (!this._closing) {
console.log('[core] Daemon caught a promise rejection, exiting...')
await this.shutdown()
this._closing = true
}
const msg = String(reason)
if (throws) {
throw new Error(msg)
Expand Down

0 comments on commit d739e3d

Please sign in to comment.