Commit 39dd18d
fix(connection): detect half-open sockets via TCP_USER_TIMEOUT
Symptom: you run a command and nothing comes back — the connection is actually
dead (server gone / network dropped) but the client sits "Connected", showing the
local echo with no server response, until you force a reconnect.
Cause: SO_KEEPALIVE / TcpKeepAliveTime only probe an IDLE socket. The moment a
command (or the NOP heartbeat) is sent, that data is in flight; on a half-open
peer it is never acknowledged, so keepalive doesn't run and TCP instead
retransmits the unacked data for ~15 minutes (tcp_retries2) before failing. The
read loop stays blocked the whole time, so no auto-reconnect fires.
Fix: set TCP_USER_TIMEOUT (Linux/Android) to 20s, which bounds how long
unacknowledged in-flight data is retransmitted before the OS fails the socket.
A half-open connection now surfaces in ~20s → the read loop completes → the
existing monitor auto-reconnects (and re-authenticates). It only trips on
genuinely unacked bytes, so a slow-but-alive server (still ACKing at the TCP
layer) never false-fires. Best-effort + platform-guarded; keepalive remains the
fallback elsewhere.
Verified the raw option round-trips on Linux (set 20000 → read back 20000);
Core suite (198) passes.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HHCRc5CJ6595iMzEgYYdQp1 parent 208a65a commit 39dd18d
1 file changed
Lines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
178 | 205 | | |
179 | 206 | | |
180 | 207 | | |
| |||
237 | 264 | | |
238 | 265 | | |
239 | 266 | | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
240 | 272 | | |
241 | 273 | | |
242 | 274 | | |
| |||
0 commit comments