Skip to content

Commit 1b7f1a2

Browse files
committed
fix: improve WebSocket error handling and destroy cleanup in EventClient
- Add scheduleReconnect() call in error handler for non-browser runtimes where 'close' may not follow 'error' - Reset wsGaveUp, wsReconnectAttempts, wsReconnectDelay in ___destroyNetworkTransport for safe reuse
1 parent 76907ad commit 1b7f1a2

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

packages/event-bus-client/src/plugin.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,11 @@ export class EventClient<TEventMap extends Record<string, any>> {
329329
ws.addEventListener('error', () => {
330330
this.debugLog('WebSocket connection error')
331331
this.#wsConnecting = false
332+
// In non-browser runtimes, 'close' may not follow 'error'.
333+
// Guard: only schedule reconnect if close handler hasn't already.
334+
if (!this.#wsReconnectTimer && !this.#ws) {
335+
this.scheduleReconnect()
336+
}
332337
})
333338
} catch {
334339
this.debugLog('Failed to create WebSocket connection')
@@ -575,6 +580,9 @@ export class EventClient<TEventMap extends Record<string, any>> {
575580
}
576581
this.#connected = false
577582
this.#useNetworkTransport = false
583+
this.#wsGaveUp = false
584+
this.#wsReconnectAttempts = 0
585+
this.#wsReconnectDelay = 100
578586
}
579587
}
580588

0 commit comments

Comments
 (0)