Skip to content

SysbotBase: bound the shutdown and heartbeat sends at 1 second - #1877

Merged
Mysticial merged 1 commit into
mainfrom
sbb-shutdown-send-timeout
Nov 11, 2026
Merged

Mysticial merged 1 commit into
mainfrom
sbb-shutdown-send-timeout

Conversation

@pa-devbot

Copy link
Copy Markdown
Collaborator

Summary

Fixes the audit finding "Non-reading server stalls shutdown": the destructor sends detachController before closing the socket, and write_data() used an unlimited send timeout. A peer that stops reading can stall the application's shutdown for the whole TCP retransmission timeout (or forever, if the peer never errors the connection).

Changes

write_data() now takes a send deadline (default: unlimited — the command and setup paths are unchanged) and passes it through to the socket's send(), which was given a timeout parameter by the earlier send-deadline work.

Two paths pass a 1-second deadline:

path why bounded
destructor's detachController send the detach is best-effort; the socket close that follows is what matters
heartbeat ping / getVersion sends these hold m_send_lock while the destructor's send waits for it — a heartbeat send stalled on a non-reading peer must not hold the shutdown path; 1 s matches the heartbeat's own 1 s cadence, and a timed-out ping is simply dropped (m_active_pings is capped at 60)

Testing

New regression test NintendoSwitch::SysbotBase - shutdown send is bounded against a stalled peer:

  • stands up a real ServerSocket_Qt that accepts the connection and then blocks its event thread on the first received byte (a peer that stops reading),
  • drives a real TcpSysbotBase_Connection against it,
  • verifies write_data(payload, 1s) returns within the shared 60 s budget,
  • verifies the destructor completes within the budget while the peer is still stalling (the pre-fix behavior was an unbounded hang).

The test skips (doesn't fail) on starved machines via the same timing_unreliable() probe the socket tests use; the 60 s budget only has to prove boundedness (pre-fix = infinite hang), matching the socket deadline tests' convention. 16 MiB payload reported via m_memory.

Full suite: 20,448 passed / 0 failed (5 skips = the usual audio-file environment skips).

A peer that stops reading can stall the application's shutdown: the
destructor sends detachController before closing the socket, and
write_data() used an unlimited send timeout. If the peer has filled
the send path (or stalled it in any other way), destruction blocks
for the whole TCP retransmission timeout - or forever, if the peer
never errors the connection.

write_data() now takes a send deadline (default: unlimited, so the
command and setup paths are unchanged) and passes it to the socket's
send(). Two paths use a 1-second deadline:

- The destructor's detachController send. The detach is best-effort;
  the socket close that follows is what matters.
- The heartbeat's ping/getVersion sends. These hold m_send_lock while
  the destructor's send waits for it, so a heartbeat send stalled on
  a non-reading peer must not hold the shutdown path; 1 s matches the
  heartbeat's own 1 s cadence. A timed-out ping is simply dropped
  (m_active_pings is capped at 60 entries).

The new regression test drives a real TcpSysbotBase_Connection
against a ServerSocket_Qt that accepts and then blocks its event
thread on the first received byte (a peer that stops reading). It
verifies that a write_data() with the 1-second deadline returns
within the shared 60 s budget, and that the destructor completes
within the budget even while the peer is still stalling - the
pre-fix behavior was an unbounded hang in both cases.
@Mysticial

Copy link
Copy Markdown
Collaborator

Putting on hold until a new atmosphere is released for FW 23.5.0.

@Mysticial
Mysticial merged commit b8551a7 into main Nov 11, 2026
7 of 8 checks passed
@Mysticial
Mysticial deleted the sbb-shutdown-send-timeout branch November 11, 2026 04:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants