From f796cc58e20f1c3594524c69ef0e112f37ac018f Mon Sep 17 00:00:00 2001 From: Peter Makowski Date: Wed, 26 Jun 2024 11:39:30 +0200 Subject: [PATCH] fix: limit WebSocket message backlog on reconnection (#5487) - Update WebSocket reconnection logic to prevent overwhelming the server with a flood of queued messages when the connection is re-established. --- src/websocket-client.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/websocket-client.ts b/src/websocket-client.ts index 4844d1535e..51a227f7b2 100644 --- a/src/websocket-client.ts +++ b/src/websocket-client.ts @@ -162,6 +162,10 @@ export class WebSocketClient { connect(): ReconnectingWebSocket { this.rws = new ReconnectingWebSocket(this.buildURL(), undefined, { debug: import.meta.env.VITE_APP_WEBSOCKET_DEBUG === "true", + // Limit message backlog on reconnection to prevent overwhelming the server + // with a flood of queued messages when the connection is re-established. + // Typical page load generates 5-25 messages; buffer allows for additional user actions. + maxEnqueuedMessages: 30, }); return this.rws; }