Repository navigation
fix(websocket): keep reconnect backoff when the upgrade fails - #901
Open
prestonbrown wants to merge 1 commit into
Open
prestonbrown wants to merge 1 commit into
prestonbrown wants to merge 1 commit into
Conversation
TcpClient resets the reconnect delay and retry count as soon as TCP connects, before WebSocketClient sends the upgrade request. A server that accepts TCP but rejects the upgrade (404, Sec-WebSocket-Accept mismatch, proxy with no backend) therefore reconnects at min_delay forever and never reaches max_retry_cnt. WebSocketClient now saves the backoff on connect and restores it on close unless the connection reached WS_OPENED.
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.
TcpClient resets the reconnect delay and retry count in onconnect, as soon as TCP connects. For WebSocketClient that is before the upgrade request is even sent, so a server that accepts TCP but rejects the upgrade (404 on the path, Sec-WebSocket-Accept mismatch, a reverse proxy whose backend is down) puts the client in a reconnect loop at min_delay that never backs off and never reaches max_retry_cnt. WebSocketClient now saves cur_delay and cur_retry_cnt when TCP connects and restores them on close unless the connection reached WS_OPENED, so a working session still reconnects fast after it drops. unittest/websocket_reconnect_test.cpp points a client with exponential backoff at a server that answers 404 and checks the backoff state at the fourth close: master gives
retries=1 cur_delay=0, this branch givesretries=3 cur_delay=40.