Skip to content

fix(server): detect dead clients and reclaim their sockets - #471

Merged
sjtrny merged 2 commits into
rathole-org:devfrom
tentious:fix/server-control-channel-socket-leak
Aug 22, 2026
Merged

fix(server): detect dead clients and reclaim their sockets#471
sjtrny merged 2 commits into
rathole-org:devfrom
tentious:fix/server-control-channel-socket-leak

Conversation

@tentious

@tentious tentious commented Jun 24, 2026

Copy link
Copy Markdown

Problem

Fixes #470. The server only wrote to control channels, so a half-closed client could leave its handle, data-channel pool, and service listener alive indefinitely.

Changes

  • read control channels concurrently with heartbeat and data-channel writes
  • remove a finished channel by its unique session key so reconnects are not disturbed
  • use a weak map reference so cleanup tasks cannot retain server state during shutdown
  • reject unexpected client data as a protocol violation
  • retarget and rebase the contributor change onto dev

Regression coverage

  • half-closed control channel removes both map indexes and releases the listener with heartbeat disabled
  • dropping the channel map releases the pool without a reference cycle
  • end-to-end client shutdown releases the service listener while the server remains running

Validation

  • format and docs
  • clippy and unit tests with default and rustls CI features
  • all 134 supported feature combinations
  • native-tls and rustls integration suites (8/8 each)

tentious and others added 2 commits August 22, 2026 07:42
The server never noticed a disconnected client. The control channel task
only wrote heartbeats, and writes keep succeeding on a half-closed socket,
so the ControlChannelHandle stayed in the map, its shutdown_tx never
dropped, and the data channel pool's listening sockets leaked.

Read the control channel concurrently with writes (the client sends nothing
after the handshake, so any completed read means it disconnected), and
remove the handle from the map when the control channel ends so shutdown_tx
drops and the pool is torn down.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Avoid retaining the control-channel map from cleanup tasks and treat unexpected client data as a protocol violation. Cover half-closed channels, map teardown, listener release, and heartbeat-disabled client shutdown.
@sjtrny
sjtrny changed the base branch from main to dev August 22, 2026 07:52
@sjtrny
sjtrny force-pushed the fix/server-control-channel-socket-leak branch from 47725c0 to cdb7720 Compare August 22, 2026 07:52
@sjtrny

sjtrny commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Thanks!

@sjtrny
sjtrny merged commit b044492 into rathole-org:dev Aug 22, 2026
10 checks passed
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.

Server leaks control channel handles and sockets for dead clients

2 participants