Skip to content

Commit

Permalink
fix(redis): fix master failure crashing the server (#258)
Browse files Browse the repository at this point in the history
* fix(redis): fix master failure crashing the server

* fix
  • Loading branch information
samuelmasse committed Nov 29, 2021
1 parent 91e7627 commit f745ae4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/engine/src/distributed/redis/subservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class RedisSubservice implements DistributedSubservice {
private callbacks: { [channel: string]: (message: any, channel: string) => Promise<void> } = {}
private pings!: PingPong
private scope!: string
private destroyed: boolean = false

async setup() {
this.logger.info(`Id is ${clc.bold(RedisSubservice.nodeId)}`)
Expand Down Expand Up @@ -77,14 +78,15 @@ export class RedisSubservice implements DistributedSubservice {
}

const retryStrategy = (times: number) => {
if (times > 10) {
if (this.destroyed) {
throw new Error('Unable to connect to the Redis cluster after multiple attempts')
}
return Math.min(times * 200, 5000)
}

const redisOptions: RedisOptions = {
retryStrategy
retryStrategy,
sentinelRetryStrategy: retryStrategy
}

if (_.isArray(connection)) {
Expand All @@ -100,6 +102,8 @@ export class RedisSubservice implements DistributedSubservice {
}

async destroy() {
this.destroyed = true

const now = new Date()

for (const lock of Object.values(this.locks || {})) {
Expand Down

0 comments on commit f745ae4

Please sign in to comment.