Skip to content

Commit

Permalink
连接错误处理
Browse files Browse the repository at this point in the history
  • Loading branch information
bangbang93 committed Mar 26, 2020
1 parent 1d92fe5 commit 609289a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ export class Cluster {
this.isEnabled = false
})
this.io.on('error', (err) => console.error(err))
this.io.on('connect_error', this.onConnectionError)
this.io.on('reconnect_error', this.onConnectionError)
this.io.on('connect_timeout', this.onConnectionError)
this.io.on('reconnect_timeout', this.onConnectionError)
}

public async disable(): Promise<void> {
Expand Down Expand Up @@ -218,4 +222,11 @@ export class Cluster {
this.keepAliveInterval = setTimeout(this._keepAlive.bind(this), ms('1m'))
}
}

private async onConnectionError(err): Promise<void> {
console.error('cannot connect to server', err)
this.server.close(() => {
process.exit(1)
})
}
}

0 comments on commit 609289a

Please sign in to comment.