Skip to content

Commit

Permalink
fix(sync): do not try to reconnect after end edit
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yohanboniface committed Dec 31, 2024
1 parent eb50d8a commit 424cb70
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
1 change: 1 addition & 0 deletions umap/static/umap/js/modules/sync/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class SyncEngine {
this._reconnectTimeout = null
this._reconnectDelay = RECONNECT_DELAY
this.websocketConnected = false
this.closeRequested = false
}

async authenticate() {
Expand Down
5 changes: 2 additions & 3 deletions umap/static/umap/js/modules/sync/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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()
}
Expand Down Expand Up @@ -64,7 +63,7 @@ export class WebSocketTransport {
}

close() {
this.closeRequested = true
this.receiver.closeRequested = true
this.websocket.close()
}
}

0 comments on commit 424cb70

Please sign in to comment.