Skip to content

fix(tui_gateway): enable TCP keepalive on websocket sockets (dead-peer detection) - #77977

Closed
c-pompa wants to merge 1 commit into
NousResearch:mainfrom
c-pompa:fix/ws-keepalive-dead-peer
Closed

fix(tui_gateway): enable TCP keepalive on websocket sockets (dead-peer detection)#77977
c-pompa wants to merge 1 commit into
NousResearch:mainfrom
c-pompa:fix/ws-keepalive-dead-peer

Conversation

@c-pompa

@c-pompa c-pompa commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Without SO_KEEPALIVE a silently-dropped client (SSH tunnel reset, laptop sleep, NAT timeout) leaves the TCP leg half-open forever: receive_text() blocks indefinitely and the disconnect teardown (detach, orphan reap, resume replay) never runs. The server then leaks the session and never reclaims its orphans.

_disable_nagle already reaches the raw socket, so enable keepalive there: SO_KEEPALIVE on, plus TCP_KEEPIDLE=30s / TCP_KEEPINTVL=10s / TCP_KEEPCNT=3 on Linux and TCP_KEEPALIVE=30s on macOS. A dead peer is now detected in ~60s instead of never. Best-effort like the Nagle tuning — any failure to reach the socket is logged at debug and skipped.

Tests: new tests/tui_gateway/test_ws_keepalive.py fakes the socket and pins SO_KEEPALIVE + the platform-specific idle tuning, plus the no-transport no-raise path. tests/tui_gateway: 336 passed.

We run this as a downstream production patch; flagged as incoming in our #64182 comment.

…r detection)

Without SO_KEEPALIVE a silently-dropped client (SSH tunnel reset, laptop
sleep, NAT timeout) leaves the TCP leg half-open forever: receive_text()
blocks indefinitely and the disconnect teardown (detach, orphan reap,
resume replay) never runs. The server then leaks the session and never
reclaims its orphans.

_disable_nagle already reaches the raw socket, so enable keepalive there:
SO_KEEPALIVE on, plus TCP_KEEPIDLE=30s / TCP_KEEPINTVL=10s /
TCP_KEEPCNT=3 on Linux and TCP_KEEPALIVE=30s on macOS. A dead peer is now
detected in ~60s instead of never. Best-effort like the Nagle tuning —
any failure to reach the socket is logged at debug and skipped.

Tests: new tests/tui_gateway/test_ws_keepalive.py fakes the socket and
pins SO_KEEPALIVE + the platform-specific idle tuning, plus the
no-transport no-raise path. tests/tui_gateway: 336 passed.
@c-pompa c-pompa changed the title fix(tui_gateway): enable TCP keepalive on websocket sockets (dead-pee… fix(tui_gateway): enable TCP keepalive on websocket sockets (dead-peer detection) Aug 3, 2026
@alt-glitch alt-glitch added type/bug Something isn't working comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Aug 3, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Merged via ring-2 consolidated PR #93430 — your commit cherry-picked with authorship preserved (TCP keepalive on WS sockets, complementing the new dashboard.ws_ping_* app-level keepalive). Thanks @c-pompa!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants