mirror of
https://gitlab.com/bramw/baserow.git
synced 2025-04-10 23:50:12 +00:00
Merge branch '358-prevent-reconnect-when-the-websocket-closes-without-failure' into 'develop'
Resolve "Prevent reconnect when the WebSocket closes without failure" Closes #358 See merge request bramw/baserow!187
This commit is contained in:
commit
9b0b31ad68
2 changed files with 16 additions and 3 deletions
|
@ -3,6 +3,7 @@
|
|||
## Unreleased
|
||||
|
||||
* Prevent websocket reconnect loop when the authentication fails.
|
||||
* Prevent websocket reconnect when the connection closes without error.
|
||||
* Added gunicorn worker test to the CI pipeline.
|
||||
|
||||
## Released (2021-03-01)
|
||||
|
|
|
@ -26,6 +26,12 @@ export class RealTimeHandler {
|
|||
|
||||
const token = this.context.store.getters['auth/token']
|
||||
|
||||
// If the user is already connected to the web socket, we don't have to do
|
||||
// anything.
|
||||
if (this.connected) {
|
||||
return
|
||||
}
|
||||
|
||||
// Check if we already had a failed authentication response from the server before.
|
||||
// If so, and if the authentication token has not changed, we don't need to connect
|
||||
// because we already know it will fail.
|
||||
|
@ -82,14 +88,20 @@ export class RealTimeHandler {
|
|||
* want to miss any important real time updates. After the first attempt we want to
|
||||
* delay retry with 5 seconds.
|
||||
*/
|
||||
this.socket.onclose = () => {
|
||||
this.socket.onclose = (event) => {
|
||||
this.connected = false
|
||||
// By default the user not subscribed to a page a.k.a `null`, so if the current
|
||||
// page is already null we can mark it as subscribed.
|
||||
this.subscribedToPage = this.page === null
|
||||
|
||||
// Automatically reconnect after the given timeout.
|
||||
this.delayedReconnect()
|
||||
// Automatically reconnect after the given timeout if the socket closes not
|
||||
// normally.
|
||||
// 1000=CLOSE_NORMAL
|
||||
// 1001=CLOSE_GOING_AWAY
|
||||
// 1002+=an error.
|
||||
if (event.code > 1001) {
|
||||
this.delayedReconnect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue