feat: daemon accept loop honours --max-connections admission cap#4042
Merged
Conversation
Wire `ConnectionCounter::active()` (previously `#[allow(dead_code)]`) into the accept loop. When `--max-connections N` is set and N worker guards are live, the next accepted socket is refused with `@ERROR: max connections (N) reached -- try again later\n` and dropped without spawning a thread, while the accept loop continues. upstream: clientserver.c:744-756 - `claim_connection()` emits the same wording for per-module caps via `io_printf(f_out, ...)`. Closes the daemon-scalability admission gap surfaced by the thread-per-connection audit at `docs/audits/daemon-thread-per-connection-1673.md`.
oferchen
added a commit
that referenced
this pull request
May 18, 2026
Wire `ConnectionCounter::active()` (previously `#[allow(dead_code)]`) into the accept loop. When `--max-connections N` is set and N worker guards are live, the next accepted socket is refused with `@ERROR: max connections (N) reached -- try again later\n` and dropped without spawning a thread, while the accept loop continues. upstream: clientserver.c:744-756 - `claim_connection()` emits the same wording for per-module caps via `io_printf(f_out, ...)`. Closes the daemon-scalability admission gap surfaced by the thread-per-connection audit at `docs/audits/daemon-thread-per-connection-1673.md`.
oferchen
added a commit
that referenced
this pull request
May 18, 2026
Wire `ConnectionCounter::active()` (previously `#[allow(dead_code)]`) into the accept loop. When `--max-connections N` is set and N worker guards are live, the next accepted socket is refused with `@ERROR: max connections (N) reached -- try again later\n` and dropped without spawning a thread, while the accept loop continues. upstream: clientserver.c:744-756 - `claim_connection()` emits the same wording for per-module caps via `io_printf(f_out, ...)`. Closes the daemon-scalability admission gap surfaced by the thread-per-connection audit at `docs/audits/daemon-thread-per-connection-1673.md`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ConnectionCounter::active()into the daemon accept loop so a configurable concurrent-connection ceiling is actually enforced; the helper previously carried#[allow(dead_code)]and was never consulted.--max-connections Nto the daemon CLI parser, with duplicate detection mirroring--max-sessions.@ERROR: max connections (N) reached -- try again later\n(matching upstreamclientserver.c:744-756byte for byte), the socket is dropped, no worker thread is spawned, and the accept loop continues serving future connections.--max-connectionsthe daemon behaves exactly as before.This implements task D1 from the daemon-scalability audit added in #4023 (
docs/audits/daemon-thread-per-connection-1673.md). Under high concurrency (10k+ conns) the daemon previously panicked withclone3: EAGAIN; with this change it gracefully refuses excess clients instead.Test plan
cargo fmt --allcrates/daemon/src/daemon/sections/server_runtime/tests.rs:accept_loop_refuses_when_at_capacity- two guards held, third connect receives the exact upstream wording and the counter is left at 2.accept_loop_recovers_after_disconnect- same setup, dropping one guard re-admits the next connect.refuse_if_at_capacity_admits_when_no_cap_configured- guard count is irrelevant when the cap is unset.crates/daemon/src/daemon/runtime_options/tests.rscover the option, zero/non-numeric rejection, and duplicate detection.--max-connectionsis unset).