1
0
Fork 0
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 

See merge request 
This commit is contained in:
Bram Wiepjes 2021-03-09 16:05:33 +00:00
commit 9b0b31ad68
2 changed files with 16 additions and 3 deletions
changelog.md
web-frontend/modules/core/plugins

View file

@ -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)

View file

@ -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()
}
}
}