Repository navigation
fix(server): an accept() error no longer ends the server (#200) - #201
Conversation
Any accept() error returned from the accept loop (`accepted?`), and the
binary exited, dropping every session. Under systemd's default soft
NOFILE of 1024, about 200 concurrent exec sessions (5 descriptors each)
are enough: the next accept() fails with EMFILE.
accept() errors are now classified:
- out of descriptors or buffers (EMFILE, ENFILE, ENOBUFS, ENOMEM):
warn, stop accepting for 1 s (the listener stays readable, so an
immediate retry would spin), keep serving live connections;
- the listening socket itself is unusable (EBADF, ENOTSOCK, EINVAL):
return the error, as before, so a service manager restarts the server;
- anything else is one failed pending connection: debug, retry at once,
so a peer cannot stall the loop.
Tests: accept_errors_are_classified (unit); accept_resources.rs fills
the descriptor table so the server's accept() hits EMFILE, checks the
loop is still running, then frees the descriptors and gets a banner
from a fresh connection. With EMFILE fatal again it fails ("the accept
loop ended on EMFILE"). Under systemd with LimitNOFILE=40 the unit now
stays active and logs "pausing accepts" instead of failing.
Fixes #200
Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW
Signed-off-by: Gonzalo Fleming <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
APIError: Insufficient Balance (request_id: 659e8240-e269-49d1-9afe-123ede905519) |
…rn one connection claude-review on #201: a SELinux/AppArmor denial (EACCES/EPERM) fails accept() on the listener before the connection is dequeued, so the catch-all "retry at once" would spin at 100% CPU, visible only at debug. The classes are now: - Listener (EBADF, ENOTSOCK, EINVAL): fatal, unchanged; - Connection, only the errors known to concern one dequeued connection (ECONNABORTED, ECONNRESET and the network errors accept(2) passes on): retry at once, so a peer cannot stall the loop; - Pause, everything else (resources, policy denials, unknown errors): warn and stop accepting for 1 s. The unit test moves EACCES/EPERM and non-OS errors to Pause. Refs #200 Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW Signed-off-by: Gonzalo Fleming <[email protected]>
|
APIError: Insufficient Balance (request_id: 6285e15a-d8ce-4b9d-bfe5-e33b469b655f) |
PR Review: fix(server): an accept() error no longer ends the server (#200)Decision: 🟢 Approved Executive summaryThis PR fixes a real availability bug: under descriptor pressure, Previous issues
No new findings reach the reporting threshold. |
Signed-off-by: Gonzalo Fleming <[email protected]> # Conflicts: # CHANGELOG.md
|
APIError: Insufficient Balance (request_id: d4f11f88-6b82-4533-bac7-76f98315c576) |
Resolves the conflicts with #197 (squashed ADR-0043: keep this branch's Accepted status and Links), #201 (Server::serve: its # Errors doc with this branch's loop_rx signature) and the CHANGELOG Fixed section. Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW Signed-off-by: Gonzalo Fleming <[email protected]>
Summary
An
accept()error no longer ends the server. Before, any error leaving the accept loop (accepted?inServer::serve) made the binary exit and drop every session. Under systemd's default softNOFILEof 1024, about 200 concurrentexecsessions at 5 descriptors each are enough to trigger it: the nextaccept()fails withEMFILE.Fixes #200
Motivation
This is a bug fix in the plain-PR lane. ADR-0028 decides the accept loop and its caps but says nothing about
accept()errors, and its default cap of 256 connections was supposed to bound descriptors.serve's own doc already limited the error return to failures "at the listener level". This PR makes the code match that.Raising
RLIMIT_NOFILEat startup, option 2 in #200, is not included: it changes the server's resource posture and needs its own decision.Type of change
Changes
server.rs:classify_accept_errorsorts anaccept()error into one of three classes (rustix::io::Errno::from_io_error):EBADF,ENOTSOCK,EINVAL): the listening socket itself is unusable. The error is returned as before, so a service manager can restart the server.ECONNABORTED,ECONNRESET, and the network errors accept(2) passes on (EPROTO,ENOPROTOOPT,EOPNOTSUPP,ENETDOWN,ENETUNREACH,EHOSTDOWN,EHOSTUNREACH). These get adebugand an immediate retry, so a peer cannot stall the loop.EMFILE,ENFILE,ENOBUFS,ENOMEM), security-module denials (EACCES,EPERM; claude-review) and unknown errors. These get awarn, and the loop stops accepting forACCEPT_BACKOFF(1 s).CHANGELOG.md: aFixedentry.Checklist
git commit -s).cargo fmt --allandcargo clippy --workspace --all-targets -- -D warningslocally.docs/, orREADME.md) where appropriate.CHANGELOG.mdentry under## [Unreleased]if this change is user-visible.cargo deny check. (No new dependency.rustixis already a dependency of the core.)Security considerations
max_half_open, exactly as before.ECONNABORTED/ECONNRESETor a network error on its own connection cannot buy a second of non-accepting with it.warnonce per second.unsafe, no new dependency.Tests
server.rsunit testaccept_errors_are_classified: eachErrnoof the three classes, includingEACCES/EPERMand a non-OS error in the pause class.tests/accept_resources.rs, a separate binary because it lowers this process'sRLIMIT_NOFILE:accept()getsEMFILE;EMFILEfatal again (a local mutation), the test fails with "the accept loop ended on EMFILE".LimitNOFILE=40,Type=exec), the reproduction from server: any accept() error ends the server (EMFILE at ~200 exec sessions under systemd's default NOFILE limit) #200 that ended inaccept loop failed: Too many open files/result=exit-codenow leaves the unitactive, loggingaccept failed: out of resources; pausing acceptsthree times.rust:1.99.0-bookwormin Docker: clippy is clean, and the same counts pass.Notes for reviewers
Server::servein the same region as feat(systemd): Type=notify readiness, reference unit and operator guide (ADR-0043) #198, which changes its signature to take the loop's receiver. Whichever merges second gets a small, mechanical conflict, which I will resolve.Automated reviews
PRs authored by
dependabot[bot](and other bots) do not trigger opencode or Claude Code Review. Codex reviews through the Codex cloud GitHub App (ADR-0037).They are covered by CI (
commit-lint,build (ubuntu-latest)andbuild (macos-latest)— fmt, clippy, tests, release build —,cargo deny,openssh-interop;cargo auditruns weekly, not per PR) and manual review when needed.https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW