fix(ios): add jitter to reconnection backoff to prevent thundering herd#593
Open
bianbiandashen wants to merge 1 commit intoamantus-ai:mainfrom
Open
fix(ios): add jitter to reconnection backoff to prevent thundering herd#593bianbiandashen wants to merge 1 commit intoamantus-ai:mainfrom
bianbiandashen wants to merge 1 commit intoamantus-ai:mainfrom
Conversation
When many clients disconnect simultaneously (e.g., server restart or network outage), they all attempt to reconnect at the same exponential intervals. This causes a 'thundering herd' effect where all clients hit the server at the same moment, potentially overwhelming it. Changes: - Add jitter parameter (default 30%) to ReconnectionManager.calculateBackoff() - Update performReconnection() to use the new jitter-enabled backoff - Add jitter to BufferWebSocketClient reconnection delay - Add max reconnect attempts (10) to BufferWebSocketClient to prevent infinite retry loops The jitter spreads reconnection attempts over time by adding a random delay of 0-30% of the base delay. For example, with a 16s base delay: - Without jitter: all clients retry at exactly 16s - With 30% jitter: clients retry between 16s and 20.8s
niklassaers
added a commit
to niklassaers/vibetunnel
that referenced
this pull request
Feb 26, 2026
Add jitter to exponential backoff in both BufferWebSocketClient and ReconnectionManager to prevent thundering herd on server restart. Cap BufferWebSocketClient reconnection at 10 attempts. Integrates PR amantus-ai#593.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add jitter (randomization) to exponential backoff in iOS reconnection logic to prevent the "thundering herd" problem.
Problem
When many iOS clients disconnect simultaneously (e.g., server restart, network outage, or app background/foreground transition), they all use identical exponential backoff intervals:
This causes all clients to hit the server at exactly the same moments, creating load spikes that can:
Solution
Add jitter (randomization) to spread reconnection attempts:
With 30% jitter on a 16s base delay:
This spreads the load and allows the server to recover gracefully.
Additional Fix: Max Reconnect Attempts
Also added a maximum reconnect limit (10 attempts) to
BufferWebSocketClientto prevent infinite retry loops when the server is permanently unavailable.Files Changed
ios/VibeTunnel/Services/ReconnectionManager.swiftjitterFactorparameter tocalculateBackoff()performReconnection()to use jitterios/VibeTunnel/Services/BufferWebSocketClient.swiftscheduleReconnect()maxReconnectAttemptsconstant (10)Test Plan