1
0
mirror of https://github.com/mattermost/focalboard.git synced 2025-02-04 19:15:49 +02:00

Adds a retry count to the websocket re-open flow (#4722)

* Adds a retry count to the websocket re-open flow

* Fix linter
This commit is contained in:
Miguel de la Cruz 2023-04-26 22:41:27 +02:00 committed by GitHub
parent acc9750d97
commit 799b8ead1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -127,6 +127,8 @@ class WSClient {
onUnfollowBlock: FollowChangeHandler = () => {} onUnfollowBlock: FollowChangeHandler = () => {}
private notificationDelay = 100 private notificationDelay = 100
private reopenDelay = 3000 private reopenDelay = 3000
private reopenRetryCount = 0
private reopenMaxRetries = 10
private updatedData: UpdatedData = {Blocks: [], Categories: [], BoardCategories: [], Boards: [], BoardMembers: [], CategoryOrder: []} private updatedData: UpdatedData = {Blocks: [], Categories: [], BoardCategories: [], Boards: [], BoardMembers: [], CategoryOrder: []}
private updateTimeout?: NodeJS.Timeout private updateTimeout?: NodeJS.Timeout
private errorPollId?: NodeJS.Timeout private errorPollId?: NodeJS.Timeout
@ -400,6 +402,7 @@ class WSClient {
ws.onopen = () => { ws.onopen = () => {
Utils.log('WSClient webSocket opened.') Utils.log('WSClient webSocket opened.')
this.state = 'open' this.state = 'open'
this.reopenRetryCount = 0
// if has a token defined when connecting, authenticate // if has a token defined when connecting, authenticate
if (this.token) { if (this.token) {
@ -426,19 +429,25 @@ class WSClient {
Utils.log(`WSClient websocket onclose, code: ${e.code}, reason: ${e.reason}`) Utils.log(`WSClient websocket onclose, code: ${e.code}, reason: ${e.reason}`)
if (ws === this.ws) { if (ws === this.ws) {
// Unexpected close, re-open // Unexpected close, re-open
Utils.logError('Unexpected close, re-opening websocket') Utils.logError('Unexpected WSClient close')
for (const handler of this.onStateChange) { for (const handler of this.onStateChange) {
handler(this, 'close') handler(this, 'close')
} }
this.state = 'close' this.state = 'close'
setTimeout(() => {
// ToDo: assert that this actually runs the onopen if (this.reopenRetryCount < this.reopenMaxRetries) {
// contents (auth + this.subscribe()) setTimeout(() => {
this.open() this.reopenRetryCount++
for (const handler of this.onReconnect) { Utils.log(`Reopening websocket connection, count: ${this.reopenRetryCount}`)
handler(this)
} this.open()
}, this.reopenDelay) for (const handler of this.onReconnect) {
handler(this)
}
}, this.reopenDelay)
} else {
Utils.logError('Reached max websocket re-opening attempts')
}
} }
} }