·6 min read
A 10 second timeout failed an 11.3 second handshake
I was watching courier frames against the real server when the first connection attempt failed with a timeout, and the second one, from the same machine seconds later, connected almost instantly. That pattern is easy to wave away as flaky network. I did not want to wave it away, because in Chiti a failed handshake is not just a delay. It is a gap in which the phone receives nothing, and the server will never fill that gap in afterwards.
- Project
- Chiti
- Date
- Sep 2026
- Stack
- React Native, Socket.IO
- Commit
- 05f3837
- Live
- chiti.com.ge
What broke
Chiti is a delivery and taxi app, and its real-time layer is a single Socket.IO connection per session. The rewrite I was leading had just replaced eleven scattered connections with one, so that one connection had to be boring and reliable.
It was not. On some attempts the client logged a connect_error with the message timeout, backed off, and tried again. The retry usually worked. From the app's side that looked like a brief hiccup, and the status of the connection recovered on its own.
The part that mattered was what happened in between. The backend is a legacy server. When a client is not connected, an order status ping or a position frame raised in that window is simply gone. There is no replay, no sequence number, nothing to ask for on reconnect. The client's only recovery is to invalidate its queries and refetch the truth, which brings back state but not the moments in between.
So a timeout on a slow handshake was a small data loss every time, on the connections where the link was already at its worst.
What the code showed
The socket options had a timeout that was already there from the first version of the module, and ten seconds looks generous:
const socket = io(url, {
transports: ['websocket'],
timeout: 10_000, // the connect budget
// ...reconnect options, auth callback
});Nothing about that line is wrong in the abstract. The problem was a number I had never measured. When I timed the handshake against the real server, it took 11.3 seconds. A 10 second budget was not generous, it was 1.3 seconds short, and it was short in a way that depended on luck. When the server answered a little sooner, the connection succeeded. When it answered at its measured pace, the client gave up just before the answer arrived, closed the attempt, and started a new one from zero.
That also explained the observation that started this. The second attempt connected at once. Whatever the server does during a slow first handshake, a connection made right after it was fast, so the cost landed on the first attempt, the one that most needed patience.
There was a second number I had to respect: the server's own ping timeout, which is 20 seconds. Socket.IO has two separate ideas of "this connection is dead". One is the connect timeout on the client, which governs how long a new attempt may take. The other is the ping and pong cycle, which governs a connection that was established and then went quiet. If the connect timer is shorter than a normal handshake, it races the mechanism that is actually built to tell a stalled link from a slow one, and it wins for the wrong reasons.
The fix
05f3837 (Sep 2026) changed one value and wrote down why. The timeout went from 10 seconds to 25 seconds. The reasoning lives in a comment next to the number, because a bare 25_000 invites the next engineer to tidy it back to something round.
Old connect timeout
Measured handshake
Server ping timeout
New connect timeout
The number is chosen against two figures, not one. It is above the observed handshake, so a slow attempt can finish. It is above the server's 20 second ping timeout, so that the connection is declared dead by the ping cycle and not by a timer that was guessed in advance.
The commit message says it in two lines: the measured handshake is 11.3 seconds, and a 10 second budget failed the first attempt and lost every frame raised during the reconnect. I kept the message short on purpose and put the longer argument in the code, where it will be read when someone wants to change the value.
A longer timeout has a cost, and I should be honest about it. If the server is genuinely unreachable, a user waits up to 25 seconds for a single attempt to fail rather than 10. The app's reconnect policy still retries with backoff and jitter, and the connection status is visible in the UI, so the wait is not silent. I accepted that trade because a user on a bad link who is waiting is better off than a user whose position or order update has vanished.
What I would do differently
I would measure first and choose the number second. I had a default that looked reasonable and I trusted it, and the evidence that it was wrong only turned up because I was watching frames with a script. A timing that matters this much deserves a small measurement at the start of the project, repeated from a phone on mobile data and not only from a laptop, with several samples instead of one.
I would also ask the server team, or read the server's configuration, for its real ping timings before picking any client timeout. The 20 second ping timeout was the number that gave the 25 second budget its meaning, and I only reasoned from it after the fact.
Lastly, I would make the cost of a failed attempt visible earlier. The status strip in the app counts connect errors so it can tell a handshake in flight from a connection that cannot be made. If I had logged how long successful handshakes took, the 11.3 seconds would have been sitting in a log from the first day and not found by hand.
Where this fits
This was one of the first production fixes I made to the socket layer, and it set the tone for the rest: write the number down with its reason, and treat the server as something that fails quietly. The later work on acknowledged positions and token refresh follows the same idea. You can read the whole story in the full Chiti case study, including how one typed connection replaced eleven.
The full project story shows the architecture this timeout lives in and the other incidents that real devices taught me.
Read the full case study#socket-io#react-native#debugging#timeouts
Keep reading
Have a project in mind?