Skip to content

fix(websocket): keep reconnect backoff when the upgrade fails - #901

Open
prestonbrown wants to merge 1 commit into
ithewei:masterfrom
prestonbrown:fix/ws-upgrade-backoff
Open

prestonbrown wants to merge 1 commit into
ithewei:masterfrom
prestonbrown:fix/ws-upgrade-backoff

Conversation

@prestonbrown

Copy link
Copy Markdown
Contributor

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 gives retries=3 cur_delay=40.

make unittest && LD_LIBRARY_PATH=lib bin/websocket_reconnect_test

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant