Skip to content

fix: bound WebSocket reconnect attempts - #78

Open
luojiyin1987 wants to merge 4 commits into
cv-cat:masterfrom
luojiyin1987:fix/websocket-reconnect-policy
Open

fix: bound WebSocket reconnect attempts#78
luojiyin1987 wants to merge 4 commits into
cv-cat:masterfrom
luojiyin1987:fix/websocket-reconnect-policy

Conversation

@luojiyin1987

@luojiyin1987 luojiyin1987 commented Aug 20, 2026

Copy link
Copy Markdown

Summary

  • Move live WebSocket reconnects out of the close callback.
  • Add exponential backoff with a 30-second delay cap.
  • Limit live WebSocket reconnects to five attempts per process.
  • Stop reconnecting after KeyboardInterrupt or SystemExit.
  • Retry only expected WebSocket and operating system connection errors.
  • Do not retry setup, parsing, signature, or program errors.
  • Apply auto_reconnect to both direct-message connection errors.

Retry policy

The retry budget covers the full start_ws() call. A successful connection does not reset it. This keeps a hard upper limit on reconnects.

Verification

  • Run python -m unittest discover -s tests -v.
  • Run seven reconnect policy tests.
  • Compile all changed Python modules with py_compile.
  • Verify user interrupts stop the reconnect loop.
  • Verify remote closes still use bounded backoff.
  • Verify setup and program errors propagate without retries.
  • Verify auto_reconnect=False blocks both connection error types.

Closes #79

@luojiyin1987
luojiyin1987 marked this pull request as ready for review August 20, 2026 09:23
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.

修复 WebSocket 重连策略和异常判断

1 participant