Skip to content

Research: std-only bounded-server patterns for the HTTP listener #27

Closed

Description

@tonibergholm

Part of #24

Question

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.

Activity

  1. self-assigned this
    on Jul 10, 2026
  2. tonibergholm commented on Jul 10, 2026

    @tonibergholm
    MemberAuthor

    Resolution

    Research complete. Asset: docs/research/bounded-server-patterns.md (lands on main via PR #36, awaiting merge).

    Key findings:

    • 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.
    • All four bounds sit at the accept/TcpStream/byte-count layer — compatible with Decide: transport confidentiality for sc+http (audit High #1) #26's incoming rustls wrap; PROTOCOL_VERSION stays 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

wayfinder:researchWayfinder ticket: AFK research → markdown summary

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions