Skip to content

Commit

Permalink
fix(sync): do not try to reconnect after end edit (#2412)
Browse files Browse the repository at this point in the history
We now set the "closeRequested" on the receiver itself, otherwise 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 authored Jan 1, 2025
2 parents 4164db3 + 424cb70 commit ebae9a8
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 ebae9a8

Please sign in to comment.