Skip to content

Commit

Permalink
fix: 被踹时不要硬退出,改为软重启
Browse files Browse the repository at this point in the history
  • Loading branch information
bangbang93 committed May 12, 2024
1 parent b08f616 commit 7bc0c86
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/keepalive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,14 @@ export class Keepalive {
})
if (!status) {
logger.fatal('kicked by server')
this.cluster.exit(1)
return await this.restart()
}
this.keepAliveError = 0
} catch (e) {
this.keepAliveError++
logger.error(e, 'keep alive error')
if (this.keepAliveError >= 1) {
await Bluebird.try(async () => {
await this.cluster.disable()
this.cluster.connect()
await this.cluster.enable()
})
.timeout(ms('10m'), 'restart timeout')
.catch((e) => {
logger.error(e, 'restart failed')
this.cluster.exit(1)
})
if (this.keepAliveError >= 3) {
await this.restart()
}
} finally {
void this.schedule()
Expand Down Expand Up @@ -90,4 +81,17 @@ export class Keepalive {
this.cluster.counters.bytes -= counters.bytes
return !!date
}

private async restart(): Promise<void> {
await Bluebird.try(async () => {
await this.cluster.disable()
this.cluster.connect()
await this.cluster.enable()
})
.timeout(ms('10m'), 'restart timeout')
.catch((e) => {
logger.error(e, 'restart failed')
this.cluster.exit(1)
})
}
}

0 comments on commit 7bc0c86

Please sign in to comment.