Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious where does this 5000 come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an initially chosen value to distribute the potential surge traffic across 5 seconds.

We can tune this value in the future if needed.

const delay = baseDelay + jitter
this.logging.log(
`WebSocket will attempt reconnection ${this.reconnectAttempts}/${this.maxReconnectAttempts} in ${delay}s`
)
Expand Down
Loading