fix: add receive timeout to WebSocket to prevent silent hangs #98
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The hand-rolled WebSocket client (
ws_client.nim) uses blockingsocket.recv()with no timeout. If the server disappears without sending a close frame (network flap, server crash), the main thread hangs indefinitely. No logs, no error, no recovery. The bot becomes a silent corpse.Solution
Set
SO_RCVTIMEOon the socket viasocket.setSockOpt(OptRcvTimeo, timeout)and add error handling when receive times out — detect disconnection, log it, and clean up gracefully.Files
src/robocode_tankroyale_botapi/ws_client.nimsrc/robocode_tankroyale_botapi/bot.nim(receive loop error handling)Fixed in v1.0.2. Added 30s SO_RCVTIMEO on WebSocket socket via stdlib timeout overload. 5 consecutive timeouts trigger disconnect. Validated with 3-round battle test — no false positives during normal gameplay.