fix(sync): do not try to reconnect after end edit (#2412)
Some checks failed
Test & Docs / docs (push) Has been cancelled
Test & Docs / tests (postgresql, 3.10) (push) Has been cancelled
Test & Docs / tests (postgresql, 3.12) (push) Has been cancelled
Test & Docs / lint (push) Has been cancelled

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.
This commit is contained in:
Yohan Boniface 2025-01-01 11:31:32 +01:00 committed by GitHub
commit ebae9a8cd0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View file

@ -61,6 +61,7 @@ export class SyncEngine {
this._reconnectTimeout = null this._reconnectTimeout = null
this._reconnectDelay = RECONNECT_DELAY this._reconnectDelay = RECONNECT_DELAY
this.websocketConnected = false this.websocketConnected = false
this.closeRequested = false
} }
async authenticate() { async authenticate() {

View file

@ -5,7 +5,6 @@ const FIRST_CONNECTION_TIMEOUT = 2000
export class WebSocketTransport { export class WebSocketTransport {
constructor(webSocketURI, authToken, messagesReceiver) { constructor(webSocketURI, authToken, messagesReceiver) {
this.receiver = messagesReceiver this.receiver = messagesReceiver
this.closeRequested = false
this.websocket = new WebSocket(webSocketURI) this.websocket = new WebSocket(webSocketURI)
@ -16,7 +15,7 @@ export class WebSocketTransport {
this.websocket.addEventListener('message', this.onMessage.bind(this)) this.websocket.addEventListener('message', this.onMessage.bind(this))
this.websocket.onclose = () => { this.websocket.onclose = () => {
console.log('websocket closed') console.log('websocket closed')
if (!this.closeRequested) { if (!this.receiver.closeRequested) {
console.log('Not requested, reconnecting...') console.log('Not requested, reconnecting...')
this.receiver.reconnect() this.receiver.reconnect()
} }
@ -64,7 +63,7 @@ export class WebSocketTransport {
} }
close() { close() {
this.closeRequested = true this.receiver.closeRequested = true
this.websocket.close() this.websocket.close()
} }
} }