Skip to content

harden(l1): cap the connections a relay holds at once (H7) - #4

Open
croc100 wants to merge 1 commit into
harden/h8-refuse-when-site-unreachablefrom
harden/h7-connection-cap
Open

croc100 wants to merge 1 commit into
harden/h8-refuse-when-site-unreachablefrom
harden/h7-connection-cap

Conversation

@croc100

@croc100 croc100 commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Closes ROADMAP H7: no connection limits anywhere.

Stacked on #3 (H8). Its base is harden/h8-refuse-when-site-unreachable. Merge #3 first; GitHub then retargets this PR to main.

Problem

Serve started one goroutine per accept with no bound, and every unauthenticated connection also opened a connection to the borrowed site. A flood therefore exhausted the relay and was passed on to a site the relay does not own.

Change

  • Config.MaxConns: default DefaultMaxConns = 256. Exposed on cmd/node as -max-conns.
  • Serve takes a slot before Accept and releases it when the connection's handling ends, whether a Warren session or a splice.
  • At the cap the relay stops calling Accept. New connections wait in the kernel backlog, and once it fills their SYNs go unanswered. That is an overloaded server, not a Warren-specific refusal, and it applies to probes and Warren clients alike. Choosing whom to refuse would mean reading connections first, which recreates the split H8 removed.
  • The site's footprint is bounded by the same number. Only a held client connection or the warm pool ever dials the site, so at most MaxConns + warmPoolSize connections reach it. No separate upstream cap was needed (the backlog had planned one in the warm pool; reasoning is in the ROADMAP row).
  • Handler doc: a connection counts against the cap until the handler returns.

Known residuals (in ROADMAP/CHANGELOG)

  • No per-source limit. A per-address cap would be a distinguisher costing a few dozen connections.
  • Filling the cap is observable, at the price of holding MaxConns connections.
  • Connect-close churn is relayed to the site at the attacker's own rate: a reflection with a factor of about one, not amplification.

Tests (conncap_test.go)

  • TestServeHoldsAtMostMaxConns: fills a cap of 2, checks a 3rd connection is not served, frees a slot, then checks the 3rd is served. Checked against the cap removed: it fails.
    • Its first version could not fail. The over-cap connection sent only 4 bytes, so even an uncapped relay sat in the 5 s ClientHello sniff and the 500 ms check passed anyway. It now sends a plaintext request that is spliced immediately.
  • TestConfigMaxConnsDefault: an unset or negative cap falls back to the default.

Locally (Windows): go build, go vet, go test ./... and LF-normalised gofmt all pass. CI covers -race.

🤖 Generated with Claude Code

Serve started a goroutine per accept with no bound, and every unauthenticated
connection also opened one to the borrowed site, so a flood exhausted the relay
and was passed on to a site it does not own.

Config.MaxConns (default 256, -max-conns on cmd/node) caps connections held at
once, Warren sessions and splices alike. At the cap the relay stops calling
Accept, so new connections wait in the kernel backlog and then go unanswered,
the way an overloaded server behaves, and nothing distinguishes probes from
Warren clients. Only held connections and the warm pool dial the site, so its
footprint is bounded at MaxConns + warmPoolSize.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant