You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Research: std-only bounded-server patterns for the HTTP listener #27
What do robust std-only (or minimal-dep) TCP servers do about connection bounds, and what fits serve_http_listener? Survey: bounded thread pools without crates, idle/progress deadlines on long transfers (the current opening timeout is cleared before wire::serve — crates/repo/src/http_transport.rs), aggregate spool/transfer size caps for .sc/tmp pack spooling (crates/repo/src/wire.rs), accept-loop backoff under fd exhaustion, and prior art (git-daemon, sshd MaxStartups). Deliverable: a markdown summary linked from this ticket.
A fourth gap, named: ADR-0036/THREAT-MODEL list three open consequences (thread-per-connection, no idle watchdog, no accept backoff) — but the aggregate pack spool is unbounded too, and neither document names it. Verified and pinned: read-only clients DO reach the spool-before-reject path — wire.rs:678 spools the full pack to .sc/tmp before replying EC_READONLY (the drain is deliberate, for connection sync); read_pack_stream loops with no total cap. Only per-frame/per-record caps exist (MAX_OBJECT_SIZE).
git's receive.maxInputSize is the missing spool cap's exact shape: counts bytes and dies mid-stream when exceeded (builtin/index-pack.c), and ships unlimited by default — the precedent is the knob's existence, not a number.
The idle-deadline fix is nearly free: with P25's chunked stream (≤1 MiB frames), a per-syscall set_read_timeout IS a progress-based deadline — slow-but-flowing multi-GiB transfers never trip it, only genuine stalls do. The current code already sets a 30s opening timeout and then clears it (http_transport.rs:597-599); the fix is not clearing it + adding set_write_timeout for the GetPack send side (a client that stops reading parks the thread in a blocking write today). std semantics: handle both WouldBlock (Unix) and TimedOut (Windows); timeout must be connection-fatal for a framed protocol.
Connection-limit prior art: git-daemon defaults to 32 (0=unlimited); when full it SIGTERMs the oldest same-address duplicate, sleeps 1s, then drops the incoming connection. sshd MaxStartups (10:30:100) random-early-drops only unauthenticated connections — the pre/post-auth distinction pairs with LoginGraceTime (sc's 30s opening timeout is already the stricter analogue).
The Rust Book thread pool is a poor fit (unbounded mpsc queue, and a wire "job" is a whole session); Go's LimitListener semaphore shape — permit-before-accept, ~20 lines of std Rust, kernel backlog absorbs bursts — fits better. tiny_http ships no bounds at all; minimal-dep Rust prior art offers nothing to borrow.
Accept backoff, from Go's source: 5ms doubling to 1s, reset on success; Go's Errno.Temporary() explicitly includes EMFILE/ENFILE, which is what makes the backoff cover fd exhaustion. libev documents the busy-loop failure mode and the reserved-fd shed trick.
Framing for decision ticket #28: knob-by-knob (connection limit, idle/progress deadline, spool cap, accept backoff) with candidate mechanisms, default candidates from prior art, and operator-knob shapes — see the doc's final section.
Activity
tonibergholm commentedon Jul 10, 2026
Resolution
Research complete. Asset: docs/research/bounded-server-patterns.md (lands on main via PR #36, awaiting merge).
Key findings:
wire.rs:678spools the full pack to.sc/tmpbefore replyingEC_READONLY(the drain is deliberate, for connection sync);read_pack_streamloops with no total cap. Only per-frame/per-record caps exist (MAX_OBJECT_SIZE).receive.maxInputSizeis the missing spool cap's exact shape: counts bytes and dies mid-stream when exceeded (builtin/index-pack.c), and ships unlimited by default — the precedent is the knob's existence, not a number.set_read_timeoutIS a progress-based deadline — slow-but-flowing multi-GiB transfers never trip it, only genuine stalls do. The current code already sets a 30s opening timeout and then clears it (http_transport.rs:597-599); the fix is not clearing it + addingset_write_timeoutfor the GetPack send side (a client that stops reading parks the thread in a blocking write today). std semantics: handle bothWouldBlock(Unix) andTimedOut(Windows); timeout must be connection-fatal for a framed protocol.MaxStartups(10:30:100) random-early-drops only unauthenticated connections — the pre/post-auth distinction pairs withLoginGraceTime(sc's 30s opening timeout is already the stricter analogue).LimitListenersemaphore shape — permit-before-accept, ~20 lines of std Rust, kernel backlog absorbs bursts — fits better. tiny_http ships no bounds at all; minimal-dep Rust prior art offers nothing to borrow.Errno.Temporary()explicitly includesEMFILE/ENFILE, which is what makes the backoff cover fd exhaustion. libev documents the busy-loop failure mode and the reserved-fd shed trick.TcpStream/byte-count layer — compatible with Decide: transport confidentiality for sc+http (audit High #1) #26's incoming rustls wrap;PROTOCOL_VERSIONstays 3 in every combination.Framing for decision ticket #28: knob-by-knob (connection limit, idle/progress deadline, spool cap, accept backoff) with candidate mechanisms, default candidates from prior art, and operator-knob shapes — see the doc's final section.
docs(research): bounded-server patterns for sc serve --http (#27) (#36)