From 0bbf36b0835e806d0c2bbb7644f1d6366b63e778 Mon Sep 17 00:00:00 2001 From: Jiatong Li Date: Tue, 24 Jun 2025 14:15:10 -0700 Subject: [PATCH] fix(amazonq): add jitter for websocket client re-connections --- .../src/language-server/workspaceContext/client.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/client.ts b/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/client.ts index 20c0c74467..7f05329dd0 100644 --- a/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/client.ts +++ b/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/client.ts @@ -82,7 +82,9 @@ export class WebSocketClient { // Apply exponential backoff for both unclean closures and failed reconnection attempts if (this.reconnectAttempts < this.maxReconnectAttempts) { this.reconnectAttempts++ - const delay = Math.min(1000 * Math.pow(2, this.reconnectAttempts), 30000) + const baseDelay = Math.min(1000 * Math.pow(2, this.reconnectAttempts), 30000) + const jitter = Math.random() * 5000 // jitter of 0 ~ 5000 milliseconds + const delay = baseDelay + jitter this.logging.log( `WebSocket will attempt reconnection ${this.reconnectAttempts}/${this.maxReconnectAttempts} in ${delay}s` )