Skip to content

Fix server connection accept path robustness - #32

Merged
NikolaiShipilov merged 9 commits into
mainfrom
fix/server-accept-robustness
Nov 19, 2026
Merged

NikolaiShipilov merged 9 commits into
mainfrom
fix/server-accept-robustness

Conversation

@NikolaiShipilov

Copy link
Copy Markdown
Collaborator

Brief

Harden the server's accept phase (before the websocket upgrade) so one misbehaving client can no longer block, stall, or corrupt the upgrade of other connections.

Description

Previously the server kept one shared buffer and request object for reading upgrade requests, and only re-armed the acceptor after the current connection's upgrade request had been read. This allowed:

  • a malformed request to leave stale bytes in the shared buffer, breaking the upgrade of the next connection;
  • a client that connects but sends nothing to stop the server from accepting any further connections;
  • such a silent client to hold its socket and buffers open forever.

Changes:

  • Give each connection its own flat_buffer and request object for the upgrade request, instead of the shared acceptBuffer/acceptRequest members (removed from Server class members)
  • Re-arm the acceptor immediately after accepting a connection, without waiting for its upgrade request
  • Add a 5 s timeout on reading the upgrade request; a client that sends nothing is disconnected. The timeout is cleared once the request has been read, and the websocket layer handles timeouts after the upgrade
  • Add test_server_accept.cpp, which drives the accept phase with raw TCP sockets:
    • MalformedRequestDoesNotPoisonLaterConnections
    • SilentClientDoesNotBlockOtherConnections
    • SilentClientIsDisconnected

Replaces the closed wider scope #31

NikolaiShipilov and others added 4 commits October 28, 2026 14:54
Co-authored-by: Anže Škerjanc <95276291+anzeskerjancDS@users.noreply.github.com>
…upgrade request

Co-authored-by:  Anže Škerjanc <95276291+anzeskerjancDS@users.noreply.github.com>
Co-authored-by:  Anže Škerjanc <95276291+anzeskerjancDS@users.noreply.github.com>
A client that connects but never sends the HTTP upgrade request used to
hold its socket and buffers open forever. The pre-upgrade read now
expires after 5s and the connection is closed.

Co-authored-by:  Anže Škerjanc <95276291+anzeskerjancDS@users.noreply.github.com>
@NikolaiShipilov NikolaiShipilov self-assigned this Nov 18, 2026
@NikolaiShipilov NikolaiShipilov added the bug Something isn't working label Nov 18, 2026
Signal the server connection only after the user context is stored,
the test thread reads it right after the wait.
Write handlers queued past the deadline can still run after the test
body returns, so they must not reference its stack locals. Hold the
completed-writes counter in a shared atomic instead of capturing a
local size_t by reference (also removes the data race on it).
@NikolaiShipilov
NikolaiShipilov merged commit 3f18a72 into main Nov 19, 2026
7 of 11 checks passed
@NikolaiShipilov
NikolaiShipilov deleted the fix/server-accept-robustness branch November 19, 2026 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants