Menu

How do you test reconnect logic in long-lived WebSocket clients?

Reading 0:00
15s threshold

I have a Go client that keeps WebSocket connections open for days to exchange trade feeds. Reconnecting is the easy part: exponential backoff with jitter, a context per connection, and a fresh subscribe after each dial. The part I find harder to get right is what happens around the reconnect: 1. Recording the exact window when the connection was down, so the data lost in that window can be backfilled later. 2. Telling that apart from data lost while the connection was up. The server can skip sequence numbers without ever closing the socket, and from the client side the connection looks healthy. 3. Detecting a connection that is technically open but has gone silent. Ping/pong keeps passing, but no messages arrive. Today I test this with an httptest server that drops connections, skips sequence numbers and goes quiet on purpose, plus a fake clock for the timeouts. It works, but the tests feel brittle around timing. How do you test this kind of behavior?…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.