From 424cb70ac420d5754aced82f6f26db3f95a37d3e Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Tue, 31 Dec 2024 14:17:30 +0100 Subject: [PATCH] fix(sync): do not try to reconnect after end edit We now save the "closeRequested" on the receiver itself, other wise there is a race condition between the reconnect (which create a new transport) and the onclose checking closeRequest on an old transport. --- umap/static/umap/js/modules/sync/engine.js | 1 + umap/static/umap/js/modules/sync/websocket.js | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/umap/static/umap/js/modules/sync/engine.js b/umap/static/umap/js/modules/sync/engine.js index 9094b4822..212c2528e 100644 --- a/umap/static/umap/js/modules/sync/engine.js +++ b/umap/static/umap/js/modules/sync/engine.js @@ -61,6 +61,7 @@ export class SyncEngine { this._reconnectTimeout = null this._reconnectDelay = RECONNECT_DELAY this.websocketConnected = false + this.closeRequested = false } async authenticate() { diff --git a/umap/static/umap/js/modules/sync/websocket.js b/umap/static/umap/js/modules/sync/websocket.js index ce346ad76..26c99f26e 100644 --- a/umap/static/umap/js/modules/sync/websocket.js +++ b/umap/static/umap/js/modules/sync/websocket.js @@ -5,7 +5,6 @@ const FIRST_CONNECTION_TIMEOUT = 2000 export class WebSocketTransport { constructor(webSocketURI, authToken, messagesReceiver) { this.receiver = messagesReceiver - this.closeRequested = false this.websocket = new WebSocket(webSocketURI) @@ -16,7 +15,7 @@ export class WebSocketTransport { this.websocket.addEventListener('message', this.onMessage.bind(this)) this.websocket.onclose = () => { console.log('websocket closed') - if (!this.closeRequested) { + if (!this.receiver.closeRequested) { console.log('Not requested, reconnecting...') this.receiver.reconnect() } @@ -64,7 +63,7 @@ export class WebSocketTransport { } close() { - this.closeRequested = true + this.receiver.closeRequested = true this.websocket.close() } }