First, a true story from our production environment.
Users reported that messages wouldn't send — the spinner just kept spinning. But the UI said "Connected", with a nice green dot. The server logs were even weirder: those users' connections were still alive on the server. The server thought they were online, and was faithfully pushing messages into dead sockets.
Restarting the app fixed it instantly. A few hours later, it came back.
Zombie connections — also known as half-open connections. Below is everything we learned, plus the four-part reliability kit we ended up shipping. Don't ask what version one looked like. Version one was the absence of everything below.
Why TCP Lies to You
WebSocket sits on top of TCP, and TCP has a property many people only learn about in production:
If the peer drops off the network abruptly — cable unplugged, laptop asleep, Wi-Fi to 4G — your socket fires no events at all .…