Skip to content

Commit 4508575

Browse files
LiGaCuJiatong Li
authored andcommitted
fix(amazonq): add jitter for websocket client re-connections (aws#1752)
Co-authored-by: Jiatong Li <[email protected]>
1 parent 95d52a0 commit 4508575

File tree

1 file changed

+3
-1
lines changed
  • server/aws-lsp-codewhisperer/src/language-server/workspaceContext

1 file changed

+3
-1
lines changed

server/aws-lsp-codewhisperer/src/language-server/workspaceContext/client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ export class WebSocketClient {
8282
// Apply exponential backoff for both unclean closures and failed reconnection attempts
8383
if (this.reconnectAttempts < this.maxReconnectAttempts) {
8484
this.reconnectAttempts++
85-
const delay = Math.min(1000 * Math.pow(2, this.reconnectAttempts), 30000)
85+
const baseDelay = Math.min(1000 * Math.pow(2, this.reconnectAttempts), 30000)
86+
const jitter = Math.random() * 5000 // jitter of 0 ~ 5000 milliseconds
87+
const delay = baseDelay + jitter
8688
this.logging.log(
8789
`WebSocket will attempt reconnection ${this.reconnectAttempts}/${this.maxReconnectAttempts} in ${delay}s`
8890
)

0 commit comments

Comments
 (0)