edge, activator: idle and dial timeouts, cancellable health waits
From the Go audit (#1123), first batch item 3: - Public edge servers (:80, :443, dev, door, devbox TLS) close idle keep-alive connections after 120 s (publicIdleTimeout), under the NLB's 350 s default; a source test fails any edge http.Server without the timeouts. - tcpProxy dials remote upstreams through a bounded dialer (30 s), keeping 15b1ee6b's link-local refusal. - The wake health waits poll under the wake's context, so a cancelled wake stops probing at once instead of 30-120 s later. - The plan-disabled log throttle is keyed on the matched route, not the request Host, so invented subdomains cannot grow the map. Reviewed by Astra (round 1, READY AFTER FIXES; both P2s fixed in 4882aebb). Census approved on #280. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Squashed from audit-request-path into main.
20 files changed,
+602
−77
docs/superpowers/notes/census-proposal-audit-request-path.md+25 −0docs/superpowers/reviews/FINDINGS-audit-request-path-R1.md+52 −0docs/superpowers/reviews/REVIEW-BRIEF-audit-request-path.md+68 −0internal/activator/activator.go+1 −1internal/activator/backend_exec.go+36 −23internal/activator/backend_unit.go+22 −27internal/activator/healthaddr_guard_test.go+4 −3internal/activator/healthcheck_redirect_test.go+6 −5internal/activator/healthwait_cancel_test.go+141 −0internal/edge/devbox.go+3 −2internal/edge/door.go+3 −3internal/edge/edge.go+8 −6internal/edge/idletimeout_test.go+98 −0internal/edge/ingressdrain.go+27 −4internal/edge/plandisabled.go+10 −1internal/edge/plandisabled_test.go+37 −0internal/edge/upstreamdial.go+27 −2internal/edge/upstreamdial_test.go+22 −0internal/provision/testdata/plan14-root-reads-audit-request-path.tsv+11 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0
CI passed — run details
diff --git a/docs/superpowers/notes/census-proposal-audit-request-path.md b/docs/superpowers/notes/census-proposal-audit-request-path.md| new file mode 100644 |
| index 000000000..3e2673e97 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-audit-request-path.md |
| @@ -0,0 +1,25 @@ |
| +# Census approval: audit-request-path |
| + |
| +Ruling `census-ruling-audit-request-path`. The independent reviewer approves or rejects every change below, 1 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +| unit | change | read sites | what changed | |
| +|---|---|---|---| |
| +| `internal/edge/door.go` `Edge.openDoor` | body | unchanged (1) | the edge-local door server gains IdleTimeout: publicIdleTimeout (120 s) beside its ReadHeaderTimeout; comment updated. No read added. | |
| +| `internal/edge/edge.go` `RunWithActivatorReady` | body | unchanged (5) | the dev-mode http.Server gains IdleTimeout: publicIdleTimeout (120 s) beside its ReadHeaderTimeout; comment updated. Same 5 read sites, no read added. | |
| + |
| +Envelopes re-pinned: `internal/activator`, `internal/edge`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| + |
| +Recorded dispositions, which each change must still satisfy: |
| + |
| +- `internal/edge/door.go` `Edge.openDoor`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input |
| +- `internal/edge/edge.go` `RunWithActivatorReady`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-certwarm-wake;basis=registers the cert warm's nudge on OnReload and on the home map's new served-hosts wake (#386); nudge only sends on a buffered channel; no read added, same 5 sites;rev3=census-ruling-edge-roll-blip;basis=the :80/:443 (and dev) listeners are bound on the calling goroutine with net.Listen via listen()/listenAddr (same empty-address defaults as ListenAndServe) before the serve goroutines, which now call Serve/ServeTLS on them, and one log line names the bound addresses; no read added, same 5 sites;rev3=census-ruling-edge-held-streams;basis=the edge in the agent (carlos-edge.service, user carlos): the inline home-map arming (newHomeMap, one boot Refresh, Store, run) moves unchanged into the new Edge.ArmHomeMap and is called here as e.ArmHomeMap(); same refresh, same timeout, same order. The reads are moved, none added.;rev3=census-ruling-agent-start-demo-1;basis=Logs the combined explicit wildcard parents through demoWildcardDomains; no new watcher or read loop.;rev3=census-ruling-region-ha-p3a;basis=P3a Task 3: invoke the local admission Close before HTTP/HTTPS draining and door shutdown in both dev and normal listeners. Preserve merged main's startup behavior and its census basis; the same five read sites, no new reads.;rev3=census-ruling-stateless-replicas-3;basis=Task 1b: defer stopping and joining the edge's replica jobs at shutdown. Existing five direct read sites unchanged; no new reader or authority.;rev3=census-ruling-region-ha-p3b;basis=Wrap dev, HTTP and HTTPS listeners through ConfigureGroupHairpin before serving. Indirectly read protected root boot identity and group-ingress.json; kernel local/peer addresses mark local ingress, never HTTP headers. Agent edge uses verified public source for accounting; direct read sites unchanged and absent marker keeps original listeners. CI fix removes interface enumeration: local peer must match snapshot primary IPv4, an ingress IPv4 installed locally by root, or loopback; kernel destination must still be an ingress EIP on port 80/443. Merge 45cebde4 retains deferred stopReplicaProbes alongside group listener wrapping and shutdown admission closure.;rev3=census-ruling-demo-api-site-route;basis=Change the startup failure context from load routes to initialize because origin validation now runs during construction. Existing five read sites unchanged; no new read or runtime authority.;rev3=census-ruling-region-ha-graceful-terminate-t2;basis=Invoke the agent shutdown timestamp hook synchronously at SIGTERM/SIGINT receipt before closing admission in dev and TLS paths. No read added.;rev3=census-ruling-region-ha-held-build;basis=region HA held-requests Task 5: registers the https and http servers with the connection drain (conns.serve) so a drain can close idle keep-alive connections; no read added;rev3=census-ruling-warm-set-published-724;basis=#724: the inline cert warm construction (newCertWarm over warmSet and dnsGate, then OnReload and setServedWake registering warm.nudge) moves unchanged into the new Edge.newIssuerWarm in certwarm.go and is called here with the same apps domain, parents, perHostCert, warmResolver, edgeIPs and store; the loop still starts here. The warm set it wires now reads the published edges files through the home map (OwnServedHosts and ServedHosts, both already polled) instead of the local route table, regional names aside. It is a different source, not a subset: an attached name not yet published as pointing is no longer listed, while a name the route table has already dropped stays listed until this box's next edges file write and the home map's next poll catch up (HostPolicy still refuses an order for a name the registry no longer holds). A name published not pointing is not a warm candidate at all, whether or not its certificate is cached: the warm neither looks it up, orders it nor re-arms its renewal until its home box publishes it pointing again (a cached certificate keeps serving and re-arms on a handshake at the issuer). The warm reads the set only after the issuer gate, and the read is in memory (route table and the home map's last snapshot); it also drops a DNS-miss entry for a name that has left the set before probing it. It keeps a failure record while any box publishes the exact name (the home map DeployedHosts: every box's file, own included, pointing or not, the same in-memory snapshot) or the name is a regional route-table name, and prunes it only once no box publishes it. That retention set has no apps-domain or wildcard filter (those stay on candidacy only), so a name published not pointing, or one a wildcard parent starts covering, keeps the record that explains its backoff; the set is never a source of candidates. No read site added in this unit, same 5 sites.;rev3=census-ruling-w6-ingress-drain;basis=the two public servers are built by e.publicServers (internal/edge/ingressdrain.go): :443 as before (same handler, TLS config and ReadHeaderTimeout 10 s), :80 now wrapped by plainTracked so the ingress drain can count and close its requests (its barrier is never §25's); Serve's error test is listenerFailed(err) = err != nil && !errors.Is(err, http.ErrServerClosed) (was err != ErrServerClosed), so a graceful Shutdown by the drain is not fatal. New Edge.plain connDrain field. Same flags, addresses and listeners; read sites unchanged (5); no read added.;rev3=census-ruling-edge-ppv2;basis=Edge process (uid carlos), not root. Edge gains the proxy atomic.Pointer. Outside dev mode, before either public listener binds and before the ready hook hands the Edge to the agent, calls e.loadProxyIngress(os.Getenv, dataDir): CARLOS_INGRESS_PROXY_SOURCES from the edge's own environment (carlos-edge.service loads the root-owned 0600 host.env) through hostenv.ParseProxySources; blank leaves the edge unarmed with nothing read; a non-empty list arms it and Lstats <dataDir>/edge/trust-barrier (armProxyIngress); a value that does not parse is log.Fatal. After the hairpin configuration, wrapProxyIngress wraps both public listeners outermost (returns them untouched when unarmed); when armed it logs the armed line and starts runProxyJournal (counters to the journal, no reads). The existing 5 read sites are unchanged. |
| + |
| +New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff: |
| + |
| +- reads `internal/edge/plandisabled.go:Edge.planDisabledAdmit`: +registry:Host ×3; keeps legacy, task accepted-legacy |
| + |
| +Seal: `fea6bec1f00dace47aa6006bf8606602efda4cecfa4fe3c3890136c0fb27720c` → `3f7dc37d114377b168c6bc1ae48e7bf815dbc1f5a569274af642e00e7d08ca2a`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-audit-request-path.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/docs/superpowers/reviews/FINDINGS-audit-request-path-R1.md b/docs/superpowers/reviews/FINDINGS-audit-request-path-R1.md| new file mode 100644 |
| index 000000000..456c5c3d0 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/FINDINGS-audit-request-path-R1.md |
| @@ -0,0 +1,52 @@ |
| +Reviewed `origin/main...2d1f36fdbf4ee5b7b8128ba3893cda755a043d65`, base `15b1ee6b6a65a52b82075003d8d6c2bcbb100ca5`, round 1 of 3. The requested tip adds only the brief after implementation tip `9604346a`. |
| + |
| +No P1 findings. Two P2 findings follow; no P3 findings. |
| + |
| +1. **P2 — Check 2: the prober’s dial-deadline claim is incorrect.** |
| + |
| + The new comment in [upstreamdial.go:13](/home/paulca/amadan.net/carlos/platform-audit-request-path/internal/edge/upstreamdial.go:13), repeated in commit `c6ec153f`, says both `multiProxy` and the prober bound their dials with context deadlines. |
| + |
| + `multiProxy` does, inside its dial callback. The prober instead installs the unbounded `upstreamDialer().DialContext` and sets `http.Client.Timeout` and `ResponseHeaderTimeout`: [prober.go:136](/home/paulca/amadan.net/carlos/platform-audit-request-path/internal/edge/prober.go:136). Go’s transport explicitly removes request cancellation and deadlines before dialing: [transport.go:1524](/home/paulca/.local/go-dist/src/net/http/transport.go:1524). |
| + |
| + **Failure scenario:** a black-holed probe target causes the HTTP request to time out, but its connection attempt can continue until the kernel’s timeout. Later probe ticks can start additional attempts. The prober closes idle connections on `Stop`, not after each failed probe. |
| + |
| + **Fix:** correct the new comment and branch description to distinguish the HTTP request bound from the dial bound. Record the existing unbounded prober dial as follow-up work. Its eventual fix needs a deadline inside the guarded dial callback or a dialer timeout. |
| + |
| + **Fault family:** outbound connection lifetime must be bounded at the operation that owns the connection. This is a pre-existing implementation gap newly described as already covered, not a regression introduced by this branch. |
| + |
| +2. **P2 — Check 5: the cancellation test assumes an in-flight handler settles within 100 ms.** |
| + |
| + [healthwait_cancel_test.go:84](/home/paulca/amadan.net/carlos/platform-audit-request-path/internal/activator/healthwait_cancel_test.go:84) acknowledges that an already-sent probe may reach the handler after the wait returns, then uses a 100 ms sleep before taking its baseline. |
| + |
| + **Failure scenario:** a loaded runner delays that handler beyond the settling sleep. It increments `probes` during the subsequent observation window, and the test reports continued polling even though the client stopped correctly. Request cancellation does not synchronously join the server handler. |
| + |
| + **Fix:** synchronize cancellation with a controlled polling boundary and explicitly acknowledge completion of any outstanding handler. Assert that no new probe starts after cancellation; do not infer that boundary from elapsed wall time. |
| + |
| + **Fault family:** cancellation regression tests must distinguish a new probe from completion of one already sent. |
| + |
| +The remaining checks support the implementation: |
| + |
| +- **Idle timeout:** all five constructors set `publicIdleTimeout`: HTTP and HTTPS in [ingressdrain.go:96](/home/paulca/amadan.net/carlos/platform-audit-request-path/internal/edge/ingressdrain.go:96), dev in [edge.go:5171](/home/paulca/amadan.net/carlos/platform-audit-request-path/internal/edge/edge.go:5171), devbox in [devbox.go:225](/home/paulca/amadan.net/carlos/platform-audit-request-path/internal/edge/devbox.go:225), and door in [door.go:201](/home/paulca/amadan.net/carlos/platform-audit-request-path/internal/edge/door.go:201). Go applies this after an HTTP/1 request finishes; hijacked connections leave that loop. HTTP/2 inherits the setting and stops its idle timer while streams are open. Held streams, uploads, WebSockets and active tunnel traffic therefore retain their existing lifetimes. |
| +- **Timeout ordering:** `90 s < 120 s < 350 s` matches the backhaul pool and the configured TCP listeners. Terraform sets no listener idle-time override. AWS confirms the 350-second default: [https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-listeners.html](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-listeners.html). |
| +- **Upstream guard:** `tcpProxy` uses the new guarded dialer both directly and inside local retries. `multiProxy`, the prober and TCP health waits retain their guard. Resolution-time IPv4, IPv6 and mapped-address refusal remains unchanged. |
| +- **Health waits:** polling is now synchronous, requests carry the wake context, and pauses select on cancellation. Both transports close idle connections on return; Go’s implementation also cancels abandoned pending dials. There is no detached polling loop left. Transport goroutines unwind asynchronously, so this is cancellation and cleanup, not a synchronous join of every internal goroutine. |
| +- **Preserved health semantics:** responses below 500 succeed, redirects are not followed, `X-Forwarded-Proto` remains set, and the three-second per-request timeout and polling backoff remain. The overall timeout still has its previous possible final-probe overshoot. |
| +- **Callers checked:** `ExecBackend.startChildAt` ([2438](/home/paulca/amadan.net/carlos/platform-audit-request-path/internal/activator/backend_exec.go:2438)), `ExecBackend.startUnitAt` ([3176](/home/paulca/amadan.net/carlos/platform-audit-request-path/internal/activator/backend_exec.go:3176)), `ExecBackend.startRootfs` ([293](/home/paulca/amadan.net/carlos/platform-audit-request-path/internal/activator/rootfs.go:293)), `Service.genHealthy` ([518](/home/paulca/amadan.net/carlos/platform-audit-request-path/internal/activator/swap.go:518)), and both branches of `UnitBackend.waitHealthy` ([179](/home/paulca/amadan.net/carlos/platform-audit-request-path/internal/activator/backend_unit.go:179)). Existing failure cleanup remains intact. The deleted context-free helpers had no production callers besides the wrappers replaced here. |
| +- **Throttle keys:** the changed key uses the matched route’s `Host`; the request host appears only in the quoted message. I traced the other callers and found no additional unrestricted remote-input key. Apparent exceptions are constrained by exact published-host membership, registered routes/channels, validated fleet membership, or fixed complaint/path values. |
| +- **Tests and portability:** the new tests target the old missing timeout, zero-valued dialer settings, per-request-host map growth, and continued probing after cancellation. The server and dialer tests inspect configuration rather than elapsed network behavior. The new dialer test alone does not verify `tcpProxy` wiring; that wiring is correct by inspection. No new Linux-only API or type appears in the changed production code. |
| + |
| +Census verdicts for `census-ruling-audit-request-path` at the requested tip: |
| + |
| +| Unit or envelope | Verdict | Evidence and basis | |
| +|---|---|---| |
| +| `Edge.openDoor` | **APPROVE** | Read [door.go:152](/home/paulca/amadan.net/carlos/platform-audit-request-path/internal/edge/door.go:152) through its return. Only the server timeout and comment change. Socket checks, staged creation, permissions and shutdown remain unchanged. Retain `legacy / accepted-legacy`. | |
| +| `RunWithActivatorReady` | **APPROVE** | Read the function beginning at [edge.go:5061](/home/paulca/amadan.net/carlos/platform-audit-request-path/internal/edge/edge.go:5061), including dev construction and public listener wiring. No new read or authority; existing five read sites remain. Retain its disposition. | |
| +| `Edge.planDisabledAdmit` | **APPROVE** | Read [plandisabled.go:76](/home/paulca/amadan.net/carlos/platform-audit-request-path/internal/edge/plandisabled.go:76)–97. The three added `registry:Host` reads use the route already supplied. Admission predicate, status exception and fixed response remain unchanged. Retain `legacy / accepted-legacy`. | |
| +| `internal/activator` envelope | **APPROVE** | Reviewed the changed health-wait functions, `healthPause`, `probeHealth`, callers and tests. Unix control-endpoint/peer checks, TCP link-local refusal and redirect refusal remain intact. No new destination or root authority. | |
| +| `internal/edge` envelope | **APPROVE** | Reviewed the five server constructions, `tcpProxy`, both dialer helpers, disabled-route admission and tests. Changes bound connection lifetime and throttle cardinality without widening destinations, filesystem access or admission authority. | |
| + |
| +Validation was limited to source review, clean `git diff --check`, and clean `gofmt -l` on changed Go files. The permitted targeted activator test command, run at `nice -n 19` with `GOCACHE` unset, failed before compilation because the read-only sandbox prevented creation of Go’s work directory. Tests, census execution and cross-compilation are therefore unverified here. No files were edited. |
| + |
| +Round 1 stops with no P1. Apply the P2 fixes without reopening the review, retaining the required census and changed-security checks. |
| + |
| +**READY AFTER FIXES** |
| \ No newline at end of file |
diff --git a/docs/superpowers/reviews/REVIEW-BRIEF-audit-request-path.md b/docs/superpowers/reviews/REVIEW-BRIEF-audit-request-path.md| new file mode 100644 |
| index 000000000..cef95fea9 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/REVIEW-BRIEF-audit-request-path.md |
| @@ -0,0 +1,68 @@ |
| +# Review brief: branch audit-request-path, round 1 of 3 |
| + |
| +Repo carlos/platform, branch `audit-request-path`, commit 9604346a0cd833bbe39cbd5d97f5f2d6c2234083. |
| +Under review: the diff `origin/main...9604346a0cd833bbe39cbd5d97f5f2d6c2234083` (base 15b1ee6b). |
| +Authorities: AGENTS.md on main ("The census", "Stopping rules"). Context: |
| +amadan discussion #1123 (Go audit backlog, first batch item 3). |
| + |
| +You are an independent reviewer. Read the diff, then the code it touches, |
| +and check every claim in the commit messages against that code. |
| + |
| +You are also the census reviewer for this branch: the card is |
| +`docs/superpowers/notes/census-proposal-audit-request-path.md`. Give a |
| +verdict for every unit and envelope it lists, citing the lines you read, |
| +per AGENTS.md "Getting a change approved" step 4. |
| + |
| +## What to check |
| + |
| +1. IdleTimeout (120 s, `publicIdleTimeout`) on five public servers: does |
| + any of them carry long-lived traffic an idle timeout could cut (held |
| + streams #432, WebSockets #471, tunnels, hijacked connections)? Go's |
| + IdleTimeout applies only between requests on keep-alive connections; |
| + confirm nothing here relies on a different behaviour. Is 120 s right |
| + against the NLB's 350 s default and the 90 s backhaul client idle? |
| +2. `tcpUpstreamDialer` (30 s Timeout and KeepAlive): link-local refusal |
| + from 15b1ee6b still enforced on every path that used it? |
| +3. `waitHealthyCtx` / `waitHealthyAddrCtx`: cancellation is prompt, no |
| + goroutine or connection outlives the call, success and timeout paths |
| + behave as before for every caller (list the callers you checked). The |
| + deleted `waitHealthy`/`waitHealthyAddr`: truly unused outside tests? |
| +4. Plan-disabled throttle key: now built only from box-controlled values |
| + (logThrottled's contract in edge.go)? Any other logThrottled caller |
| + still keyed on remote input? |
| +5. New tests: would each fail against the old code? Do any rely on |
| + wall-clock sleeps that could flake on a loaded CI runner? |
| +6. Cross-compile: anything Linux-only in files the darwin/windows CLI |
| + build links? |
| + |
| +## Severity |
| + |
| +- **P1**: unsafe, would not compile, a test fails, or it would not work. |
| + Blocks merge. |
| +- **P2**: wrong or missing. Fixed without reopening this review. (The |
| + census, and review of any newly changed security, root, termination |
| + or production-storage behaviour, still check the fix; see AGENTS.md, |
| + "Stopping rules".) |
| +- **P3**: clarity or polish. Goes on a follow-up list; never a reason for |
| + another round. |
| + |
| +A P1 states its failure scenario and the evidence (file:line). Do not |
| +raise a P2 to P1 to keep the review open. |
| + |
| +## Output |
| + |
| +Findings ranked P1, P2, P3. Each gives the section or task, the problem, |
| +the evidence (file:line, verified), the failure scenario, a concrete |
| +fix and the invariant or trust boundary it breaks (that is its fault |
| +family). Then the census verdict per unit and envelope. End with exactly |
| +one verdict: |
| + |
| +- **READY**: no P1 and no P2. |
| +- **READY AFTER FIXES**: no P1. The listed P2s are fixed without another |
| + round. |
| +- **NOT READY**: one or more P1s, listed. |
| + |
| +Do not edit files. Do not spawn Anthropic-model reviewers or subagents of |
| +your own. Do not run the full test suites; targeted `go test -run` on a |
| +single package at `nice -n 19` is allowed if you need evidence, with |
| +GOCACHE unset. |
diff --git a/internal/activator/activator.go b/internal/activator/activator.go| index 89ee0b5a9..1aab0b8a5 100644 |
| --- a/internal/activator/activator.go |
| +++ b/internal/activator/activator.go |
| @@ -4147,7 +4147,7 @@ var errWorkerExitedEarly = errors.New("worker exited during its settle window") |
| // awaitWorkerSettle is the socketless child's health probe: it is up once it |
| // says so over the agent socket, or once it has survived sidecarSettle without |
| -// exiting. Real time, not a.now — like waitHealthy, this bounds a real |
| +// exiting. Real time, not a.now — like waitHealthyCtx, this bounds a real |
| // process's first seconds, and the test clock exists to move idle windows, not |
| // to model a boot. |
| func (a *Service) awaitWorkerSettle(ctx context.Context, e *actEntry, proc Proc) error { |
diff --git a/internal/activator/backend_exec.go b/internal/activator/backend_exec.go| index 41bb7965e..02e019c32 100644 |
| --- a/internal/activator/backend_exec.go |
| +++ b/internal/activator/backend_exec.go |
| @@ -2923,7 +2923,7 @@ func seedVars(fileEnv map[string]string, host string) map[string]string { |
| // already happened and this wins. |
| // |
| // The two guards make "only a socket THIS backend's child bound" true |
| -// rather than merely intended. waitHealthy tolerates a squatter (its own |
| +// rather than merely intended. waitHealthyCtx tolerates a squatter (its own |
| // contract: it only dials), so a child that lost the bind race with a |
| // stray supervisor (EADDRINUSE, exits) can still see the health wait |
| // succeed off the SQUATTER's answers; a dead child means the socket is |
| @@ -4031,25 +4031,50 @@ func socketClient(socket string) *http.Client { |
| } |
| } |
| -// waitHealthy blocks until the instance answers an HTTP request on its socket, |
| -// or the timeout elapses. It retries, so it's robust to the restart window |
| -// (socket briefly absent, or a stale socket left by an abruptly-killed old |
| -// process) — and a broken binary that never becomes healthy fails the wake. |
| -func waitHealthy(socket string, timeout time.Duration) error { |
| +// waitHealthyCtx blocks until the instance answers an HTTP request on its |
| +// socket, the timeout elapses, or ctx ends. It retries, so it's robust to |
| +// the restart window (socket briefly absent, or a stale socket left by an |
| +// abruptly-killed old process) — and a broken binary that never becomes |
| +// healthy fails the wake. |
| +// |
| +// When ctx ends it returns ctx.Err() and probes no more: the request in |
| +// flight is cancelled with ctx and no further one starts. An aborted wake |
| +// must not keep probing a socket nobody wants anymore, since a retried |
| +// wake binds the same path and a stale probe would land on its process. |
| +func waitHealthyCtx(ctx context.Context, socket string, timeout time.Duration) error { |
| deadline := time.Now().Add(timeout) |
| client := healthClient(socketClient(socket)) |
| + defer client.CloseIdleConnections() |
| var last error |
| var poll time.Duration |
| for time.Now().Before(deadline) { |
| - if last = probeHealth(client, "http://carlos/"); last == nil { |
| + if err := ctx.Err(); err != nil { |
| + return err |
| + } |
| + if last = probeHealth(ctx, client, "http://carlos/"); last == nil { |
| return nil |
| } |
| poll = nextHealthPoll(poll) |
| - time.Sleep(poll) |
| + if err := healthPause(ctx, poll); err != nil { |
| + return err |
| + } |
| } |
| return fmt.Errorf("instance not healthy within %s: %v", timeout, last) |
| } |
| +// healthPause waits d between two health probes, or returns ctx.Err() as |
| +// soon as ctx ends. |
| +func healthPause(ctx context.Context, d time.Duration) error { |
| + t := time.NewTimer(d) |
| + defer t.Stop() |
| + select { |
| + case <-ctx.Done(): |
| + return ctx.Err() |
| + case <-t.C: |
| + return nil |
| + } |
| +} |
| + |
| // healthClient is c made fit for a health probe: it never follows a |
| // redirect. A redirect is an answer, and under 500, so the app is up. |
| // Following one is worse than pointless: an app with Rails' force_ssl |
| @@ -4065,8 +4090,9 @@ func healthClient(c *http.Client) *http.Client { |
| // says X-Forwarded-Proto: https, as the edge does on every real request |
| // (they all arrive over TLS), so an app that redirects plain http takes its |
| // normal path rather than answering the probe with a redirect (#845). |
| -func probeHealth(client *http.Client, url string) error { |
| - req, err := http.NewRequest(http.MethodGet, url, nil) |
| +// ctx cancels the request, in flight or not yet sent. |
| +func probeHealth(ctx context.Context, client *http.Client, url string) error { |
| + req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) |
| if err != nil { |
| return err |
| } |
| @@ -4097,19 +4123,6 @@ func nextHealthPoll(d time.Duration) time.Duration { |
| return min(max(2*d, healthPollMin), healthPollMax) |
| } |
| -// waitHealthyCtx is waitHealthy bounded by ctx as well as its own timeout, so |
| -// an aborted wake doesn't keep probing a socket nobody wants anymore. |
| -func waitHealthyCtx(ctx context.Context, socket string, timeout time.Duration) error { |
| - done := make(chan error, 1) |
| - go func() { done <- waitHealthy(socket, timeout) }() |
| - select { |
| - case err := <-done: |
| - return err |
| - case <-ctx.Done(): |
| - return ctx.Err() |
| - } |
| -} |
| - |
| // readEnvFile parses a KEY=value EnvironmentFile (blank lines and #comments |
| // ignored). |
| func readEnvFile(path string) (map[string]string, error) { |
diff --git a/internal/activator/backend_unit.go b/internal/activator/backend_unit.go| index 5dff27268..63edbb2a6 100644 |
| --- a/internal/activator/backend_unit.go |
| +++ b/internal/activator/backend_unit.go |
| @@ -262,20 +262,21 @@ type unitRep struct{} |
| func (unitRep) Err() error { return nil } |
| func (unitRep) Close(context.Context) error { return nil } |
| -// waitHealthyAddr is waitHealthy for TCP upstreams (rt.Addr — unit tenants |
| -// that can't accept a unix listener yet; see the carlos-app@.socket unit's |
| -// fallback note). |
| -func waitHealthyAddr(addr string, timeout time.Duration) error { |
| - return waitHealthyAddrVia(net.Dialer{Timeout: 30 * time.Second, KeepAlive: 30 * time.Second}, addr, timeout) |
| -} |
| - |
| -// waitHealthyAddrVia is waitHealthyAddr dialing with base (a test sets its |
| -// Resolver) behind upstreamguard: rt.Addr is route-supplied, so a link-local |
| -// or IMDS destination is refused after resolution and before connect, and |
| -// that refusal ends the wait at once. The transport is the default one's |
| -// settings without the environment proxy, so the guard judges the upstream |
| -// itself rather than a proxy. |
| -func waitHealthyAddrVia(base net.Dialer, addr string, timeout time.Duration) error { |
| +// waitHealthyAddrCtx is waitHealthyCtx for TCP upstreams (rt.Addr — unit |
| +// tenants that can't accept a unix listener yet; see the |
| +// carlos-app@.socket unit's fallback note), and stops probing when ctx |
| +// ends in the same way. |
| +func waitHealthyAddrCtx(ctx context.Context, addr string, timeout time.Duration) error { |
| + return waitHealthyAddrVia(ctx, net.Dialer{Timeout: 30 * time.Second, KeepAlive: 30 * time.Second}, addr, timeout) |
| +} |
| + |
| +// waitHealthyAddrVia is waitHealthyAddrCtx dialing with base (a test sets |
| +// its Resolver) behind upstreamguard: rt.Addr is route-supplied, so a |
| +// link-local or IMDS destination is refused after resolution and before |
| +// connect, and that refusal ends the wait at once. The transport is the |
| +// default one's settings without the environment proxy, so the guard |
| +// judges the upstream itself rather than a proxy. |
| +func waitHealthyAddrVia(ctx context.Context, base net.Dialer, addr string, timeout time.Duration) error { |
| tr := http.DefaultTransport.(*http.Transport).Clone() |
| tr.Proxy = nil |
| tr.DialContext = upstreamguard.Dialer(base).DialContext |
| @@ -285,29 +286,23 @@ func waitHealthyAddrVia(base net.Dialer, addr string, timeout time.Duration) err |
| var last error |
| var poll time.Duration |
| for time.Now().Before(deadline) { |
| - if last = probeHealth(client, "http://"+addr+"/"); last == nil { |
| + if err := ctx.Err(); err != nil { |
| + return err |
| + } |
| + if last = probeHealth(ctx, client, "http://"+addr+"/"); last == nil { |
| return nil |
| } |
| if errors.Is(last, upstreamguard.ErrLinkLocal) { |
| return fmt.Errorf("instance health check: %w", last) |
| } |
| poll = nextHealthPoll(poll) |
| - time.Sleep(poll) |
| + if err := healthPause(ctx, poll); err != nil { |
| + return err |
| + } |
| } |
| return fmt.Errorf("instance not healthy within %s: %v", timeout, last) |
| } |
| -func waitHealthyAddrCtx(ctx context.Context, addr string, timeout time.Duration) error { |
| - done := make(chan error, 1) |
| - go func() { done <- waitHealthyAddr(addr, timeout) }() |
| - select { |
| - case err := <-done: |
| - return err |
| - case <-ctx.Done(): |
| - return ctx.Err() |
| - } |
| -} |
| - |
| // SplitBackend composes the two production backends behind the one Backend |
| // seam the state machine sees: each call dispatches on the route's Backing, |
| // so exec children and unit tenants share the singleflight wakes, idle |
diff --git a/internal/activator/healthaddr_guard_test.go b/internal/activator/healthaddr_guard_test.go| index 38b44aad1..7d118d7aa 100644 |
| --- a/internal/activator/healthaddr_guard_test.go |
| +++ b/internal/activator/healthaddr_guard_test.go |
| @@ -1,6 +1,7 @@ |
| package activator |
| import ( |
| + "context" |
| "errors" |
| "net" |
| "net/http" |
| @@ -24,8 +25,8 @@ func TestWaitHealthyAddrRefusesLinkLocal(t *testing.T) { |
| name string |
| wait func() error |
| }{ |
| - {"name resolving to IMDS", func() error { return waitHealthyAddrVia(base, "imds.test:80", 5*time.Second) }}, |
| - {"IMDS literal, production dialer", func() error { return waitHealthyAddr("169.254.169.254:80", 5*time.Second) }}, |
| + {"name resolving to IMDS", func() error { return waitHealthyAddrVia(context.Background(), base, "imds.test:80", 5*time.Second) }}, |
| + {"IMDS literal, production dialer", func() error { return waitHealthyAddrCtx(context.Background(), "169.254.169.254:80", 5*time.Second) }}, |
| } { |
| t.Run(tc.name, func(t *testing.T) { |
| start := time.Now() |
| @@ -43,7 +44,7 @@ func TestWaitHealthyAddrRefusesLinkLocal(t *testing.T) { |
| func TestWaitHealthyAddrLoopbackStillWorks(t *testing.T) { |
| srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) |
| t.Cleanup(srv.Close) |
| - if err := waitHealthyAddr(strings.TrimPrefix(srv.URL, "http://"), 2*time.Second); err != nil { |
| + if err := waitHealthyAddrCtx(context.Background(), strings.TrimPrefix(srv.URL, "http://"), 2*time.Second); err != nil { |
| t.Fatalf("waitHealthyAddr on loopback: %v", err) |
| } |
| } |
diff --git a/internal/activator/healthcheck_redirect_test.go b/internal/activator/healthcheck_redirect_test.go| index c7d98be84..eac83b3cc 100644 |
| --- a/internal/activator/healthcheck_redirect_test.go |
| +++ b/internal/activator/healthcheck_redirect_test.go |
| @@ -1,6 +1,7 @@ |
| package activator |
| import ( |
| + "context" |
| "net" |
| "net/http" |
| "strings" |
| @@ -51,7 +52,7 @@ func TestWaitHealthySaysHTTPS(t *testing.T) { |
| t.Fatal(err) |
| } |
| https := forceSSLApp(t, ln) |
| - if err := waitHealthy(sock, 2*time.Second); err != nil { |
| + if err := waitHealthyCtx(context.Background(), sock, 2*time.Second); err != nil { |
| t.Fatalf("waitHealthy: %v", err) |
| } |
| if https.Load() == 0 { |
| @@ -69,7 +70,7 @@ func TestWaitHealthyDoesNotFollowRedirects(t *testing.T) { |
| t.Fatal(err) |
| } |
| redirectingApp(t, ln) |
| - if err := waitHealthy(sock, 2*time.Second); err != nil { |
| + if err := waitHealthyCtx(context.Background(), sock, 2*time.Second); err != nil { |
| t.Fatalf("waitHealthy on a redirecting app: %v", err) |
| } |
| } |
| @@ -81,7 +82,7 @@ func TestWaitHealthyAddrSaysHTTPSAndDoesNotFollowRedirects(t *testing.T) { |
| t.Fatal(err) |
| } |
| https := forceSSLApp(t, ln) |
| - if err := waitHealthyAddr(ln.Addr().String(), 2*time.Second); err != nil { |
| + if err := waitHealthyAddrCtx(context.Background(), ln.Addr().String(), 2*time.Second); err != nil { |
| t.Fatalf("waitHealthyAddr: %v", err) |
| } |
| if https.Load() == 0 { |
| @@ -93,7 +94,7 @@ func TestWaitHealthyAddrSaysHTTPSAndDoesNotFollowRedirects(t *testing.T) { |
| t.Fatal(err) |
| } |
| redirectingApp(t, ln2) |
| - if err := waitHealthyAddr(ln2.Addr().String(), 2*time.Second); err != nil { |
| + if err := waitHealthyAddrCtx(context.Background(), ln2.Addr().String(), 2*time.Second); err != nil { |
| t.Fatalf("waitHealthyAddr on a redirecting app: %v", err) |
| } |
| } |
| @@ -110,7 +111,7 @@ func TestWaitHealthyStillFailsA500(t *testing.T) { |
| })} |
| go srv.Serve(ln) |
| t.Cleanup(func() { srv.Close() }) |
| - err = waitHealthyAddr(ln.Addr().String(), 200*time.Millisecond) |
| + err = waitHealthyAddrCtx(context.Background(), ln.Addr().String(), 200*time.Millisecond) |
| if err == nil || !strings.Contains(err.Error(), "HTTP 500") { |
| t.Fatalf("waitHealthyAddr on a 500 = %v, want HTTP 500", err) |
| } |
diff --git a/internal/activator/healthwait_cancel_test.go b/internal/activator/healthwait_cancel_test.go| new file mode 100644 |
| index 000000000..7f0bbdaf2 |
| --- /dev/null |
| +++ b/internal/activator/healthwait_cancel_test.go |
| @@ -0,0 +1,141 @@ |
| +package activator |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "net" |
| + "net/http" |
| + "sync/atomic" |
| + "testing" |
| + "time" |
| +) |
| + |
| +// healthWaitKinds are the two health waits a wake runs: on the instance's |
| +// unix socket (exec, rootfs, generations) and on a unit route's TCP addr. |
| +// Each listens with h and returns the wait to run against it. |
| +type healthWaitKind func(t *testing.T, h http.Handler) func(ctx context.Context) error |
| + |
| +var healthWaitKinds = map[string]healthWaitKind{ |
| + "socket": func(t *testing.T, h http.Handler) func(ctx context.Context) error { |
| + requireUnixSockets(t) |
| + sock := tmpSock(t) |
| + ln, err := net.Listen("unix", sock) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + serveHealth(t, ln, h) |
| + return func(ctx context.Context) error { return waitHealthyCtx(ctx, sock, 30*time.Second) } |
| + }, |
| + "addr": func(t *testing.T, h http.Handler) func(ctx context.Context) error { |
| + ln, err := net.Listen("tcp", "127.0.0.1:0") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + serveHealth(t, ln, h) |
| + addr := ln.Addr().String() |
| + return func(ctx context.Context) error { return waitHealthyAddrCtx(ctx, addr, 30*time.Second) } |
| + }, |
| +} |
| + |
| +func serveHealth(t *testing.T, ln net.Listener, h http.Handler) { |
| + t.Helper() |
| + srv := &http.Server{Handler: h} |
| + go srv.Serve(ln) |
| + t.Cleanup(func() { srv.Close() }) |
| +} |
| + |
| +// runWait starts wait in the background and returns its result channel. |
| +func runWait(ctx context.Context, wait func(context.Context) error) <-chan error { |
| + done := make(chan error, 1) |
| + go func() { done <- wait(ctx) }() |
| + return done |
| +} |
| + |
| +func wantCanceled(t *testing.T, done <-chan error) { |
| + t.Helper() |
| + wantCanceledWithin(t, done, time.Second) |
| +} |
| + |
| +func wantCanceledWithin(t *testing.T, done <-chan error, d time.Duration) { |
| + t.Helper() |
| + select { |
| + case err := <-done: |
| + if !errors.Is(err, context.Canceled) { |
| + t.Fatalf("wait = %v, want context.Canceled", err) |
| + } |
| + case <-time.After(d): |
| + t.Fatalf("the wait did not return within %v", d) |
| + } |
| +} |
| + |
| +// TestHealthWaitStopsProbingWhenCancelled: a wake that is cancelled while |
| +// its instance answers 503 stops probing. Before, the wait returned but |
| +// left its polling loop running for the rest of its 30 s (120 s rootfs), so |
| +// a retried wake's process on the same socket got the stale probes. |
| +func TestHealthWaitStopsProbingWhenCancelled(t *testing.T) { |
| + for name, listen := range healthWaitKinds { |
| + t.Run(name, func(t *testing.T) { |
| + // The wake is cancelled from inside the second probe's handler. |
| + // The wait sends one probe at a time, so at that moment that |
| + // probe is the only one in flight and is already counted: any |
| + // later start is a probe begun after the cancel. |
| + ctx, cancel := context.WithCancel(context.Background()) |
| + defer cancel() |
| + const cancelAt = 2 |
| + var probes atomic.Int32 |
| + wait := listen(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + if probes.Add(1) == cancelAt { |
| + cancel() |
| + } |
| + w.WriteHeader(http.StatusServiceUnavailable) |
| + })) |
| + done := runWait(ctx, wait) |
| + wantCanceledWithin(t, done, 5*time.Second) |
| + // No new probe may start across several poll intervals |
| + // (healthPollMax is 50 ms); before, the loop kept going. |
| + time.Sleep(6 * healthPollMax) |
| + if got := probes.Load(); got != cancelAt { |
| + t.Fatalf("%d probes started after the cancel; a cancelled wait must stop probing", got-cancelAt) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// TestHealthWaitCancelsTheProbeInFlight: an instance that accepts the probe |
| +// and never answers does not hold a cancelled wait's request for the |
| +// probe's 3 s client timeout; the request is cancelled with the wake. |
| +func TestHealthWaitCancelsTheProbeInFlight(t *testing.T) { |
| + for name, listen := range healthWaitKinds { |
| + t.Run(name, func(t *testing.T) { |
| + entered := make(chan struct{}, 1) |
| + released := make(chan struct{}) |
| + wait := listen(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + select { |
| + case entered <- struct{}{}: |
| + default: |
| + } |
| + <-r.Context().Done() |
| + select { |
| + case <-released: |
| + default: |
| + close(released) |
| + } |
| + })) |
| + ctx, cancel := context.WithCancel(context.Background()) |
| + defer cancel() |
| + done := runWait(ctx, wait) |
| + select { |
| + case <-entered: |
| + case <-time.After(5 * time.Second): |
| + t.Fatal("the probe never reached the instance") |
| + } |
| + cancel() |
| + wantCanceled(t, done) |
| + select { |
| + case <-released: |
| + case <-time.After(time.Second): |
| + t.Fatal("the instance still holds the probe 1s after the wake was cancelled") |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/edge/devbox.go b/internal/edge/devbox.go| index 0caff03a5..93e6dab1f 100644 |
| --- a/internal/edge/devbox.go |
| +++ b/internal/edge/devbox.go |
| @@ -218,8 +218,8 @@ func serveDevbox(ctx context.Context, cfg DevboxConfig, seams devboxSeams) error |
| go w.run() |
| go e.Watch(stop) |
| - // ReadHeaderTimeout for the same slow-header reason as Run's servers, |
| - // and no Read/WriteTimeout, which would cut proxied WebSockets. |
| + // ReadHeaderTimeout and IdleTimeout for the same reasons as Run's |
| + // servers, and no Read/WriteTimeout, which would cut proxied WebSockets. |
| selfHost, _, _ := net.SplitHostPort(cfg.ListenAddr) |
| selfIP, _ := netip.ParseAddr(selfHost) // checked before building the edge |
| srv := &http.Server{ |
| @@ -231,6 +231,7 @@ func serveDevbox(ctx context.Context, cfg DevboxConfig, seams devboxSeams) error |
| MinVersion: tls.VersionTLS12, |
| }, |
| ReadHeaderTimeout: 10 * time.Second, |
| + IdleTimeout: publicIdleTimeout, |
| ErrorLog: seams.errorLog, |
| } |
| served := make(chan error, 1) |
diff --git a/internal/edge/door.go b/internal/edge/door.go| index 12c9b0206..67533f788 100644 |
| --- a/internal/edge/door.go |
| +++ b/internal/edge/door.go |
| @@ -196,9 +196,9 @@ func (e *Edge) openDoor(path string) (closeDoor func(), err error) { |
| ln.Close() |
| return nil, err |
| } |
| - // ReadHeaderTimeout for the public listeners' Slowloris reason; no |
| - // Read/WriteTimeout, which would cut long-lived streams. |
| - srv := &http.Server{Handler: http.HandlerFunc(e.serveDoor), ReadHeaderTimeout: 10 * time.Second} |
| + // ReadHeaderTimeout and IdleTimeout for the public listeners' reasons; |
| + // no Read/WriteTimeout, which would cut long-lived streams. |
| + srv := &http.Server{Handler: http.HandlerFunc(e.serveDoor), ReadHeaderTimeout: 10 * time.Second, IdleTimeout: publicIdleTimeout} |
| go func() { |
| if err := srv.Serve(ln); err != nil && !errors.Is(err, http.ErrServerClosed) { |
| log.Printf("edge: edge-local door on %s stopped: %v", path, err) |
diff --git a/internal/edge/edge.go b/internal/edge/edge.go| index 6eeba4de1..86e490c37 100644 |
| --- a/internal/edge/edge.go |
| +++ b/internal/edge/edge.go |
| @@ -4009,12 +4009,13 @@ func unixProxy(socketPath string) *httputil.ReverseProxy { |
| // A loopback upstream is this box's own process, so a refused dial there is |
| // a restart in progress: the dial is retried for hold.dial (one deadline |
| // fixed per dial) instead of 502ing at once. hold.dial <= 0, or a remote |
| -// addr, dials once. Either way the dial is upstreamDialer's (hold.dialer is |
| -// nil in production), which refuses link-local and IMDS addresses. |
| +// addr, dials once. Either way the dial is tcpUpstreamDialer's (hold.dialer |
| +// is nil in production), which refuses link-local and IMDS addresses and |
| +// gives up on a connect after tcpUpstreamDialTimeout. |
| func tcpProxy(addr string, hold localHold) *httputil.ReverseProxy { |
| dial := hold.dialer |
| if dial == nil { |
| - dial = upstreamDialer().DialContext |
| + dial = tcpUpstreamDialer().DialContext |
| } |
| tr := &http.Transport{ |
| MaxIdleConns: 32, |
| @@ -5164,9 +5165,10 @@ func RunWithActivatorReady(args []string, act Activator, cache *Cache, ready fun |
| log.Printf("edge: edge-local door off in dev mode") |
| } |
| // ReadHeaderTimeout guards against Slowloris-style slow-header |
| - // connection exhaustion. No ReadTimeout/WriteTimeout — those would |
| - // break long-lived proxied WebSockets. |
| - srv := &http.Server{Addr: *httpAddr, Handler: e, ReadHeaderTimeout: 10 * time.Second} |
| + // connection exhaustion; publicIdleTimeout closes idle keep-alives. |
| + // No ReadTimeout/WriteTimeout — those would break long-lived |
| + // proxied WebSockets. |
| + srv := &http.Server{Addr: *httpAddr, Handler: e, ReadHeaderTimeout: 10 * time.Second, IdleTimeout: publicIdleTimeout} |
| // Bound here, on this goroutine, as ListenAndServe would; the line |
| // below means the bind succeeded. |
| ln, err := listen("http", *httpAddr, ":http") |
diff --git a/internal/edge/idletimeout_test.go b/internal/edge/idletimeout_test.go| new file mode 100644 |
| index 000000000..39c624372 |
| --- /dev/null |
| +++ b/internal/edge/idletimeout_test.go |
| @@ -0,0 +1,98 @@ |
| +package edge |
| + |
| +import ( |
| + "crypto/tls" |
| + "go/ast" |
| + "go/parser" |
| + "go/token" |
| + "net/http" |
| + "os" |
| + "path/filepath" |
| + "strings" |
| + "testing" |
| + "time" |
| +) |
| + |
| +// TestPublicServersCloseIdleConnections: :80 and :443 close a connection |
| +// that sits idle, keep the slow-header bound, and set no Read/WriteTimeout |
| +// (they would cut uploads, held streams and WebSockets). The idle bound |
| +// stays under the region NLB's 350 s TCP idle timeout. |
| +func TestPublicServersCloseIdleConnections(t *testing.T) { |
| + e := &Edge{} |
| + h := http.NotFoundHandler() |
| + httpsSrv, httpSrv := e.publicServers(h, h, &tls.Config{}, "", "") |
| + for name, srv := range map[string]*http.Server{"https": httpsSrv, "http": httpSrv} { |
| + if srv.IdleTimeout != publicIdleTimeout || srv.ReadHeaderTimeout != 10*time.Second { |
| + t.Errorf("%s: IdleTimeout %v ReadHeaderTimeout %v, want %v and 10s", name, srv.IdleTimeout, srv.ReadHeaderTimeout, publicIdleTimeout) |
| + } |
| + if srv.ReadTimeout != 0 || srv.WriteTimeout != 0 { |
| + t.Errorf("%s: ReadTimeout %v WriteTimeout %v, want neither", name, srv.ReadTimeout, srv.WriteTimeout) |
| + } |
| + } |
| + if publicIdleTimeout <= 0 || publicIdleTimeout >= 350*time.Second { |
| + t.Fatalf("publicIdleTimeout %v must be positive and under the NLB's 350 s", publicIdleTimeout) |
| + } |
| +} |
| + |
| +// TestEveryEdgeServerSetsIdleTimeout reads the package's source: every |
| +// http.Server literal sets IdleTimeout and ReadHeaderTimeout and neither |
| +// ReadTimeout nor WriteTimeout, so a listener added later (or the dev, |
| +// devbox and door servers, built inline) cannot quietly hold idle |
| +// connections forever. The one exception is purge.go's control listener, |
| +// a per-instance unix socket that only the box's own processes can dial, |
| +// which is not public and is left as it was. |
| +func TestEveryEdgeServerSetsIdleTimeout(t *testing.T) { |
| + exempt := map[string]bool{"purge.go": true} |
| + files, err := filepath.Glob("*.go") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + fset := token.NewFileSet() |
| + found := 0 |
| + for _, name := range files { |
| + if strings.HasSuffix(name, "_test.go") || exempt[name] { |
| + continue |
| + } |
| + src, err := os.ReadFile(name) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + f, err := parser.ParseFile(fset, name, src, 0) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + ast.Inspect(f, func(n ast.Node) bool { |
| + lit, ok := n.(*ast.CompositeLit) |
| + if !ok { |
| + return true |
| + } |
| + sel, ok := lit.Type.(*ast.SelectorExpr) |
| + if !ok || sel.Sel.Name != "Server" { |
| + return true |
| + } |
| + if pkg, ok := sel.X.(*ast.Ident); !ok || pkg.Name != "http" { |
| + return true |
| + } |
| + found++ |
| + keys := map[string]bool{} |
| + for _, el := range lit.Elts { |
| + if kv, ok := el.(*ast.KeyValueExpr); ok { |
| + if id, ok := kv.Key.(*ast.Ident); ok { |
| + keys[id.Name] = true |
| + } |
| + } |
| + } |
| + at := fset.Position(lit.Pos()) |
| + if !keys["IdleTimeout"] || !keys["ReadHeaderTimeout"] { |
| + t.Errorf("%s: http.Server without IdleTimeout and ReadHeaderTimeout", at) |
| + } |
| + if keys["ReadTimeout"] || keys["WriteTimeout"] { |
| + t.Errorf("%s: http.Server sets ReadTimeout or WriteTimeout, which cut long streams", at) |
| + } |
| + return true |
| + }) |
| + } |
| + if found < 5 { |
| + t.Fatalf("found %d http.Server literals, want at least 5 (:80, :443, dev, devbox, door); has the scan stopped matching?", found) |
| + } |
| +} |
diff --git a/internal/edge/ingressdrain.go b/internal/edge/ingressdrain.go| index 54370928f..01710b7ea 100644 |
| --- a/internal/edge/ingressdrain.go |
| +++ b/internal/edge/ingressdrain.go |
| @@ -89,14 +89,37 @@ func (e *Edge) plainTracked(h http.Handler) http.Handler { |
| // address :80's health check never reaches plainTracked or the challenge. |
| // |
| // ReadHeaderTimeout guards the public front door against Slowloris-style |
| -// slow-header connection exhaustion. No ReadTimeout/WriteTimeout: those |
| -// would break long-lived proxied WebSockets. |
| +// slow-header connection exhaustion, and publicIdleTimeout closes the |
| +// connections that sit idle between requests. No ReadTimeout/WriteTimeout: |
| +// those would break long uploads, edge-held streams (#432) and long-lived |
| +// proxied WebSockets (#471). |
| func (e *Edge) publicServers(https, challenge http.Handler, tlsCfg *tls.Config, httpAddr, httpsAddr string) (httpsSrv, httpSrv *http.Server) { |
| - httpSrv = &http.Server{Addr: httpAddr, Handler: e.plainTracked(challenge), ReadHeaderTimeout: 10 * time.Second} |
| - httpsSrv = &http.Server{Addr: httpsAddr, Handler: https, TLSConfig: tlsCfg, ReadHeaderTimeout: 10 * time.Second} |
| + httpSrv = &http.Server{Addr: httpAddr, Handler: e.plainTracked(challenge), ReadHeaderTimeout: 10 * time.Second, IdleTimeout: publicIdleTimeout} |
| + httpsSrv = &http.Server{Addr: httpsAddr, Handler: https, TLSConfig: tlsCfg, ReadHeaderTimeout: 10 * time.Second, IdleTimeout: publicIdleTimeout} |
| return httpsSrv, httpSrv |
| } |
| +// publicIdleTimeout is how long a server the edge exposes (:80, :443, the |
| +// dev listener, the devbox listener and the edge-local door) keeps a |
| +// connection with no request on it: an HTTP/1.1 keep-alive connection |
| +// between requests, or an HTTP/2 connection with no open stream. With |
| +// IdleTimeout and ReadTimeout both zero, net/http keeps such a connection, |
| +// its goroutine and its TLS state for as long as the client likes; |
| +// ReadHeaderTimeout starts only at the next request's first byte. It never |
| +// touches a request in flight, an edge-held stream (an open request) or a |
| +// hijacked connection (WebSockets, tunnels), so it is safe where |
| +// ReadTimeout and WriteTimeout are not. |
| +// |
| +// It must stay under the idle timeout of the region NLB in front of a |
| +// fixed edge: AWS's TCP default of 350 s, since the listeners in |
| +// infra/modules/region-host/ingress set no tcp_idle_timeout_seconds. The |
| +// edge then closes first, with a FIN the client sees, instead of the NLB |
| +// forgetting the flow and the client's next request on it getting a reset. |
| +// It is also above the 90 s IdleConnTimeout of the edge's own backhaul |
| +// client, so a box-to-box hop's pool drops a connection before the far |
| +// edge does. |
| +const publicIdleTimeout = 120 * time.Second |
| + |
| // CloseIngress is step 3's edge half: close the public listeners |
| // gracefully, waiting up to wait (the connection wait). |
| // |
diff --git a/internal/edge/plandisabled.go b/internal/edge/plandisabled.go| index 6b55307b7..eb2198b84 100644 |
| --- a/internal/edge/plandisabled.go |
| +++ b/internal/edge/plandisabled.go |
| @@ -4,6 +4,7 @@ import ( |
| "bytes" |
| "html/template" |
| "net/http" |
| + "strconv" |
| "github.com/carlosframework/platform/internal/registry" |
| ) |
| @@ -77,7 +78,15 @@ func (e *Edge) planDisabledAdmit(w http.ResponseWriter, r *http.Request, host st |
| if f == nil || rt.Kind == "status" || !(*f)(rt, host) { |
| return true |
| } |
| - e.logThrottled("plan-disabled "+host, "plan: answered "+host+" with the disabled page (turned off after a lapse)") |
| + // Keyed on the route, never the request's host: under a catch-all every |
| + // invented label would add a map entry and a journal line |
| + // (logThrottled's contract). The line names the route and, when it |
| + // differs, the host of the request that was logged, quoted. |
| + msg := "plan: answered " + rt.Host + " with the disabled page (turned off after a lapse)" |
| + if host != rt.Host { |
| + msg += " for host " + strconv.Quote(host) |
| + } |
| + e.logThrottled("plan-disabled "+rt.Host, msg) |
| h := w.Header() |
| h.Set("Content-Type", "text/html; charset=utf-8") |
| h.Set("Cache-Control", "no-store") |
diff --git a/internal/edge/plandisabled_test.go b/internal/edge/plandisabled_test.go| index 19ace8d89..3dd12fdb0 100644 |
| --- a/internal/edge/plandisabled_test.go |
| +++ b/internal/edge/plandisabled_test.go |
| @@ -1,6 +1,7 @@ |
| package edge |
| import ( |
| + "fmt" |
| "net/http" |
| "net/http/httptest" |
| "strings" |
| @@ -110,3 +111,39 @@ func TestNoDisabledHookUnchanged(t *testing.T) { |
| t.Fatalf("a hook answering false: %d", rec.Code) |
| } |
| } |
| + |
| +// TestDisabledCatchAllLogsOncePerRoute: the throttled log line is keyed on |
| +// the route a request resolved to, never on the request's host. Under a |
| +// turned-off catch-all every invented label is answered with the page, and |
| +// all of them share one throttle entry, so a stranger cannot grow the map |
| +// (or the journal) one subdomain at a time. |
| +func TestDisabledCatchAllLogsOncePerRoute(t *testing.T) { |
| + t.Parallel() |
| + const catchAll = "*.lapsed.example" |
| + srv, backend := newGateBackend(t, "app", "") |
| + reg := openReg(t) |
| + if err := reg.Upsert(registry.Route{Host: catchAll, Kind: "instance", Addr: srv.Listener.Addr().String(), |
| + Status: "ready", App: "shop", Account: "bab"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + e, err := New(reg, &fakeActivator{}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(e.probers.Stop) |
| + e.SetPlanDisabledFor(func(rt registry.Route, _ string) bool { return rt.Host == catchAll }) |
| + |
| + const n = 50 |
| + for i := range n { |
| + host := fmt.Sprintf("invented-%d.lapsed.example", i) |
| + wantDisabledPage(t, gateDo(e, http.MethodGet, host, "/", ""), host) |
| + } |
| + if seen, _ := backend.seen(); seen != 0 { |
| + t.Fatalf("upstream saw %d requests, want none", seen) |
| + } |
| + e.logMu.Lock() |
| + defer e.logMu.Unlock() |
| + if len(e.logN) != 1 || e.logN["plan-disabled "+catchAll] != n { |
| + t.Fatalf("throttle map %v, want one entry for %s counting %d", e.logN, catchAll, n) |
| + } |
| +} |
diff --git a/internal/edge/upstreamdial.go b/internal/edge/upstreamdial.go| index 28857146e..c9b081407 100644 |
| --- a/internal/edge/upstreamdial.go |
| +++ b/internal/edge/upstreamdial.go |
| @@ -2,6 +2,7 @@ package edge |
| import ( |
| "net" |
| + "time" |
| "github.com/carlosframework/platform/internal/upstreamguard" |
| ) |
| @@ -9,8 +10,32 @@ import ( |
| // upstreamDialer is the dialer for a TCP upstream when no test dialer is set |
| // (hold.dialer nil, as in production): the plain net.Dialer the transports |
| // used before, behind upstreamguard, which refuses link-local and IMDS |
| -// addresses after resolution and before connect. tcpProxy, multiProxy and |
| -// the prober use it; unix sockets, backhaul hops and tunnels do not. |
| +// addresses after resolution and before connect. multiProxy and the prober |
| +// use it; tcpProxy uses tcpUpstreamDialer; unix sockets, backhaul hops and |
| +// tunnels use neither. multiProxy bounds each dial with a context deadline |
| +// (multiDialTimeout). The prober's dial is still unbounded: its |
| +// http.Client.Timeout and ResponseHeaderTimeout do not reach the dial, |
| +// since net/http strips the request's deadline before dialing. Bounding it |
| +// is follow-up work. |
| func upstreamDialer() *net.Dialer { |
| return upstreamguard.Dialer(net.Dialer{}) |
| } |
| + |
| +// tcpUpstreamDialTimeout and tcpUpstreamKeepAlive are tcpProxy's dial |
| +// settings. Its transport has no other bound on a connect, so without a |
| +// Timeout a black-holed remote upstream holds the request, its goroutine |
| +// and the client's connection for the kernel's connect timeout (about two |
| +// minutes on Linux) before the 502. The values are net/http's |
| +// DefaultTransport dialer, the same the activator's wake health check uses |
| +// on these route addrs (waitHealthyAddr): a real handshake finishes far |
| +// inside 30 s, so nothing that connects today stops connecting. |
| +const ( |
| + tcpUpstreamDialTimeout = 30 * time.Second |
| + tcpUpstreamKeepAlive = 30 * time.Second |
| +) |
| + |
| +// tcpUpstreamDialer is upstreamDialer with tcpProxy's connect bound and |
| +// keep-alive: still behind upstreamguard, so the link-local refusal holds. |
| +func tcpUpstreamDialer() *net.Dialer { |
| + return upstreamguard.Dialer(net.Dialer{Timeout: tcpUpstreamDialTimeout, KeepAlive: tcpUpstreamKeepAlive}) |
| +} |
diff --git a/internal/edge/upstreamdial_test.go b/internal/edge/upstreamdial_test.go| index 4c2d367b2..672bf1bd0 100644 |
| --- a/internal/edge/upstreamdial_test.go |
| +++ b/internal/edge/upstreamdial_test.go |
| @@ -141,3 +141,25 @@ func TestUpstreamDialSitesRefuseLinkLocal(t *testing.T) { |
| conn.Close() |
| }) |
| } |
| + |
| +// TestTCPUpstreamDialerIsBounded: tcpProxy's production dialer gives up on a |
| +// connect after tcpUpstreamDialTimeout instead of the kernel's two minutes, |
| +// keeps TCP keep-alives on, and is still behind upstreamguard. |
| +func TestTCPUpstreamDialerIsBounded(t *testing.T) { |
| + d := tcpUpstreamDialer() |
| + if d.Timeout != tcpUpstreamDialTimeout || d.KeepAlive != tcpUpstreamKeepAlive { |
| + t.Fatalf("Timeout %v KeepAlive %v, want %v and %v", d.Timeout, d.KeepAlive, tcpUpstreamDialTimeout, tcpUpstreamKeepAlive) |
| + } |
| + if d.Timeout <= 0 || d.Timeout > 30*time.Second { |
| + t.Fatalf("Timeout %v: want a bound no longer than net/http's 30 s default", d.Timeout) |
| + } |
| + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) |
| + defer cancel() |
| + conn, err := d.DialContext(ctx, "tcp", "169.254.169.254:80") |
| + if conn != nil { |
| + conn.Close() |
| + } |
| + if !errors.Is(err, upstreamguard.ErrLinkLocal) { |
| + t.Fatalf("dial err = %v, want upstreamguard.ErrLinkLocal", err) |
| + } |
| +} |
diff --git a/internal/provision/testdata/plan14-root-reads-audit-request-path.tsv b/internal/provision/testdata/plan14-root-reads-audit-request-path.tsv| new file mode 100644 |
| index 000000000..0012900d8 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-audit-request-path.tsv |
| @@ -0,0 +1,11 @@ |
| +# Census overlay audit-request-path, written by census-propose (#369). census-ruling-audit-request-path, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-audit-request-path.md. |
| +# 2 body, 0 sites, 2 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +# 1 new dispositions: 1 reads re-frozen at their disposition with the claim, 0 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other. |
| +@legacy f275da6dc384e20dd81d62616a9ef251ca4e16730c3e4d374f238811664d5d06 internal/edge/door.go Edge.openDoor legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-audit-request-path;basis=the edge-local door server gains IdleTimeout: publicIdleTimeout (120 s) beside its ReadHeaderTimeout; comment updated. No read added. file:Lstat@364 65db004d6c86118f601c46acc5abf8a51e7f964b80dc9dec2fb2f99c89a6e327 |
| +@legacy 0209ecbc124213d5822821cc046c43cd39b96dfbf032a4bc20a5959ccfbbec47 internal/edge/edge.go RunWithActivatorReady legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-certwarm-wake;basis=registers the cert warm's nudge on OnReload and on the home map's new served-hosts wake (#386); nudge only sends on a buffered channel; no read added, same 5 sites;rev3=census-ruling-edge-roll-blip;basis=the :80/:443 (and dev) listeners are bound on the calling goroutine with net.Listen via listen()/listenAddr (same empty-address defaults as ListenAndServe) before the serve goroutines, which now call Serve/ServeTLS on them, and one log line names the bound addresses; no read added, same 5 sites;rev3=census-ruling-edge-held-streams;basis=the edge in the agent (carlos-edge.service, user carlos): the inline home-map arming (newHomeMap, one boot Refresh, Store, run) moves unchanged into the new Edge.ArmHomeMap and is called here as e.ArmHomeMap(); same refresh, same timeout, same order. The reads are moved, none added.;rev3=census-ruling-agent-start-demo-1;basis=Logs the combined explicit wildcard parents through demoWildcardDomains; no new watcher or read loop.;rev3=census-ruling-region-ha-p3a;basis=P3a Task 3: invoke the local admission Close before HTTP/HTTPS draining and door shutdown in both dev and normal listeners. Preserve merged main's startup behavior and its census basis; the same five read sites, no new reads.;rev3=census-ruling-stateless-replicas-3;basis=Task 1b: defer stopping and joining the edge's replica jobs at shutdown. Existing five direct read sites unchanged; no new reader or authority.;rev3=census-ruling-region-ha-p3b;basis=Wrap dev, HTTP and HTTPS listeners through ConfigureGroupHairpin before serving. Indirectly read protected root boot identity and group-ingress.json; kernel local/peer addresses mark local ingress, never HTTP headers. Agent edge uses verified public source for accounting; direct read sites unchanged and absent marker keeps original listeners. CI fix removes interface enumeration: local peer must match snapshot primary IPv4, an ingress IPv4 installed locally by root, or loopback; kernel destination must still be an ingress EIP on port 80/443. Merge 45cebde4 retains deferred stopReplicaProbes alongside group listener wrapping and shutdown admission closure.;rev3=census-ruling-demo-api-site-route;basis=Change the startup failure context from load routes to initialize because origin validation now runs during construction. Existing five read sites unchanged; no new read or runtime authority.;rev3=census-ruling-region-ha-graceful-terminate-t2;basis=Invoke the agent shutdown timestamp hook synchronously at SIGTERM/SIGINT receipt before closing admission in dev and TLS paths. No read added.;rev3=census-ruling-region-ha-held-build;basis=region HA held-requests Task 5: registers the https and http servers with the connection drain (conns.serve) so a drain can close idle keep-alive connections; no read added;rev3=census-ruling-warm-set-published-724;basis=#724: the inline cert warm construction (newCertWarm over warmSet and dnsGate, then OnReload and setServedWake registering warm.nudge) moves unchanged into the new Edge.newIssuerWarm in certwarm.go and is called here with the same apps domain, parents, perHostCert, warmResolver, edgeIPs and store; the loop still starts here. The warm set it wires now reads the published edges files through the home map (OwnServedHosts and ServedHosts, both already polled) instead of the local route table, regional names aside. It is a different source, not a subset: an attached name not yet published as pointing is no longer listed, while a name the route table has already dropped stays listed until this box's next edges file write and the home map's next poll catch up (HostPolicy still refuses an order for a name the registry no longer holds). A name published not pointing is not a warm candidate at all, whether or not its certificate is cached: the warm neither looks it up, orders it nor re-arms its renewal until its home box publishes it pointing again (a cached certificate keeps serving and re-arms on a handshake at the issuer). The warm reads the set only after the issuer gate, and the read is in memory (route table and the home map's last snapshot); it also drops a DNS-miss entry for a name that has left the set before probing it. It keeps a failure record while any box publishes the exact name (the home map DeployedHosts: every box's file, own included, pointing or not, the same in-memory snapshot) or the name is a regional route-table name, and prunes it only once no box publishes it. That retention set has no apps-domain or wildcard filter (those stay on candidacy only), so a name published not pointing, or one a wildcard parent starts covering, keeps the record that explains its backoff; the set is never a source of candidates. No read site added in this unit, same 5 sites.;rev3=census-ruling-w6-ingress-drain;basis=the two public servers are built by e.publicServers (internal/edge/ingressdrain.go): :443 as before (same handler, TLS config and ReadHeaderTimeout 10 s), :80 now wrapped by plainTracked so the ingress drain can count and close its requests (its barrier is never §25's); Serve's error test is listenerFailed(err) = err != nil && !errors.Is(err, http.ErrServerClosed) (was err != ErrServerClosed), so a graceful Shutdown by the drain is not fatal. New Edge.plain connDrain field. Same flags, addresses and listeners; read sites unchanged (5); no read added.;rev3=census-ruling-edge-ppv2;basis=Edge process (uid carlos), not root. Edge gains the proxy atomic.Pointer. Outside dev mode, before either public listener binds and before the ready hook hands the Edge to the agent, calls e.loadProxyIngress(os.Getenv, dataDir): CARLOS_INGRESS_PROXY_SOURCES from the edge's own environment (carlos-edge.service loads the root-owned 0600 host.env) through hostenv.ParseProxySources; blank leaves the edge unarmed with nothing read; a non-empty list arms it and Lstats <dataDir>/edge/trust-barrier (armProxyIngress); a value that does not parse is log.Fatal. After the hairpin configuration, wrapProxyIngress wraps both public listeners outermost (returns them untouched when unarmed); when armed it logs the armed line and starts runProxyJournal (counters to the journal, no reads). The existing 5 read sites are unchanged.;rev3=census-ruling-audit-request-path;basis=the dev-mode http.Server gains IdleTimeout: publicIdleTimeout (120 s) beside its ReadHeaderTimeout; comment updated. Same 5 read sites, no read added. data-literal@129,data-literal@148,data-literal@284,data-literal@417,file:Open@1013 7875f163b4fee8118408ff066e7bba5c4692079ffa0fb93aa16989303b469df9 |
| +@legacy bdfe5ed96dd2db7c4a7ca9b3d8fecf0d8ff21ba65baf266d176f0f0611845f96 internal/edge/plandisabled.go Edge.planDisabledAdmit legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4d-units;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), serving only: asks the plans turned-off hook (planDisabledFor, passed the row and the request host) and answers a turned-off route with a fixed 503 page rendered from constants, before the meter, gate, cache and activator; reads only the row's kind; echoes nothing from the request (plans 4d).;rev3=census-ruling-retry-after-503;basis=the fixed 503 page status is written through UnavailableNoRetry (still no Retry-After; adds answer/box headers); body and checks unchanged; no read added;rev3=census-ruling-audit-request-path;basis=the logThrottled key is now "plan-disabled "+rt.Host (the matched route, registry data) instead of the request host; the message names rt.Host and, when it differs, the request host via strconv.Quote. The three new rt.Host reads are of the route already in hand; the predicate call, page and refusal are unchanged. registry:Host@507,registry:Host@582,registry:Host@672,registry:Kind@156,whole:Route@185 ddb568faa8f5cb076d8f2e5aed371e54a5504a5092d95e622988a9d2dbdb6f8c |
| +internal/edge/door.go Edge.openDoor legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-audit-request-path;basis=the edge-local door server gains IdleTimeout: publicIdleTimeout (120 s) beside its ReadHeaderTimeout; comment updated. No read added. file:Lstat@364 65db004d6c86118f601c46acc5abf8a51e7f964b80dc9dec2fb2f99c89a6e327 |
| +internal/edge/edge.go RunWithActivatorReady legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-certwarm-wake;basis=registers the cert warm's nudge on OnReload and on the home map's new served-hosts wake (#386); nudge only sends on a buffered channel; no read added, same 5 sites;rev3=census-ruling-edge-roll-blip;basis=the :80/:443 (and dev) listeners are bound on the calling goroutine with net.Listen via listen()/listenAddr (same empty-address defaults as ListenAndServe) before the serve goroutines, which now call Serve/ServeTLS on them, and one log line names the bound addresses; no read added, same 5 sites;rev3=census-ruling-edge-held-streams;basis=the edge in the agent (carlos-edge.service, user carlos): the inline home-map arming (newHomeMap, one boot Refresh, Store, run) moves unchanged into the new Edge.ArmHomeMap and is called here as e.ArmHomeMap(); same refresh, same timeout, same order. The reads are moved, none added.;rev3=census-ruling-agent-start-demo-1;basis=Logs the combined explicit wildcard parents through demoWildcardDomains; no new watcher or read loop.;rev3=census-ruling-region-ha-p3a;basis=P3a Task 3: invoke the local admission Close before HTTP/HTTPS draining and door shutdown in both dev and normal listeners. Preserve merged main's startup behavior and its census basis; the same five read sites, no new reads.;rev3=census-ruling-stateless-replicas-3;basis=Task 1b: defer stopping and joining the edge's replica jobs at shutdown. Existing five direct read sites unchanged; no new reader or authority.;rev3=census-ruling-region-ha-p3b;basis=Wrap dev, HTTP and HTTPS listeners through ConfigureGroupHairpin before serving. Indirectly read protected root boot identity and group-ingress.json; kernel local/peer addresses mark local ingress, never HTTP headers. Agent edge uses verified public source for accounting; direct read sites unchanged and absent marker keeps original listeners. CI fix removes interface enumeration: local peer must match snapshot primary IPv4, an ingress IPv4 installed locally by root, or loopback; kernel destination must still be an ingress EIP on port 80/443. Merge 45cebde4 retains deferred stopReplicaProbes alongside group listener wrapping and shutdown admission closure.;rev3=census-ruling-demo-api-site-route;basis=Change the startup failure context from load routes to initialize because origin validation now runs during construction. Existing five read sites unchanged; no new read or runtime authority.;rev3=census-ruling-region-ha-graceful-terminate-t2;basis=Invoke the agent shutdown timestamp hook synchronously at SIGTERM/SIGINT receipt before closing admission in dev and TLS paths. No read added.;rev3=census-ruling-region-ha-held-build;basis=region HA held-requests Task 5: registers the https and http servers with the connection drain (conns.serve) so a drain can close idle keep-alive connections; no read added;rev3=census-ruling-warm-set-published-724;basis=#724: the inline cert warm construction (newCertWarm over warmSet and dnsGate, then OnReload and setServedWake registering warm.nudge) moves unchanged into the new Edge.newIssuerWarm in certwarm.go and is called here with the same apps domain, parents, perHostCert, warmResolver, edgeIPs and store; the loop still starts here. The warm set it wires now reads the published edges files through the home map (OwnServedHosts and ServedHosts, both already polled) instead of the local route table, regional names aside. It is a different source, not a subset: an attached name not yet published as pointing is no longer listed, while a name the route table has already dropped stays listed until this box's next edges file write and the home map's next poll catch up (HostPolicy still refuses an order for a name the registry no longer holds). A name published not pointing is not a warm candidate at all, whether or not its certificate is cached: the warm neither looks it up, orders it nor re-arms its renewal until its home box publishes it pointing again (a cached certificate keeps serving and re-arms on a handshake at the issuer). The warm reads the set only after the issuer gate, and the read is in memory (route table and the home map's last snapshot); it also drops a DNS-miss entry for a name that has left the set before probing it. It keeps a failure record while any box publishes the exact name (the home map DeployedHosts: every box's file, own included, pointing or not, the same in-memory snapshot) or the name is a regional route-table name, and prunes it only once no box publishes it. That retention set has no apps-domain or wildcard filter (those stay on candidacy only), so a name published not pointing, or one a wildcard parent starts covering, keeps the record that explains its backoff; the set is never a source of candidates. No read site added in this unit, same 5 sites.;rev3=census-ruling-w6-ingress-drain;basis=the two public servers are built by e.publicServers (internal/edge/ingressdrain.go): :443 as before (same handler, TLS config and ReadHeaderTimeout 10 s), :80 now wrapped by plainTracked so the ingress drain can count and close its requests (its barrier is never §25's); Serve's error test is listenerFailed(err) = err != nil && !errors.Is(err, http.ErrServerClosed) (was err != ErrServerClosed), so a graceful Shutdown by the drain is not fatal. New Edge.plain connDrain field. Same flags, addresses and listeners; read sites unchanged (5); no read added.;rev3=census-ruling-edge-ppv2;basis=Edge process (uid carlos), not root. Edge gains the proxy atomic.Pointer. Outside dev mode, before either public listener binds and before the ready hook hands the Edge to the agent, calls e.loadProxyIngress(os.Getenv, dataDir): CARLOS_INGRESS_PROXY_SOURCES from the edge's own environment (carlos-edge.service loads the root-owned 0600 host.env) through hostenv.ParseProxySources; blank leaves the edge unarmed with nothing read; a non-empty list arms it and Lstats <dataDir>/edge/trust-barrier (armProxyIngress); a value that does not parse is log.Fatal. After the hairpin configuration, wrapProxyIngress wraps both public listeners outermost (returns them untouched when unarmed); when armed it logs the armed line and starts runProxyJournal (counters to the journal, no reads). The existing 5 read sites are unchanged.;rev3=census-ruling-audit-request-path;basis=the dev-mode http.Server gains IdleTimeout: publicIdleTimeout (120 s) beside its ReadHeaderTimeout; comment updated. Same 5 read sites, no read added. data-literal@129,data-literal@148,data-literal@284,data-literal@417,file:Open@1013 7875f163b4fee8118408ff066e7bba5c4692079ffa0fb93aa16989303b469df9 |
| +internal/edge/plandisabled.go Edge.planDisabledAdmit legacy accepted-legacy accepted-legacy;rev3=census-ruling-plans-4d-units;basis=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), serving only: asks the plans turned-off hook (planDisabledFor, passed the row and the request host) and answers a turned-off route with a fixed 503 page rendered from constants, before the meter, gate, cache and activator; reads only the row's kind; echoes nothing from the request (plans 4d).;rev3=census-ruling-retry-after-503;basis=the fixed 503 page status is written through UnavailableNoRetry (still no Retry-After; adds answer/box headers); body and checks unchanged; no read added;rev3=census-ruling-audit-request-path;basis=the logThrottled key is now "plan-disabled "+rt.Host (the matched route, registry data) instead of the request host; the message names rt.Host and, when it differs, the request host via strconv.Quote. The three new rt.Host reads are of the route already in hand; the predicate call, page and refusal are unchanged. registry:Host@507,registry:Host@582,registry:Host@672,registry:Kind@156,whole:Route@185 ddb568faa8f5cb076d8f2e5aed371e54a5504a5092d95e622988a9d2dbdb6f8c |
| +@coverage internal/activator 4a6ba8b7a5cb6825bc01a14f4d842f67535795edbf0eb2ea50ea68eed6d8c526 |
| +@coverage internal/edge c7041387d997edeea3b2dad2a51bda009c9c0767888ad50af879d1a638a94ee1 |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index c6b70708e..164b0856c 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -234,3 +234,4 @@ plan14-root-reads-free-storage-250.tsv 9206205b2a3bf27b8b85310f4a44f94ef0c5886d8 |
| plan14-root-reads-fleet-first-reconcile-speed-4.tsv 4eda67fee53800e2cfa4177b954c7f0fce6bdfcfbfe1aa2547ddcec3027b668b |
| plan14-root-reads-sec-edge-redirect-linklocal.tsv 4eda67fee53800e2cfa4177b954c7f0fce6bdfcfbfe1aa2547ddcec3027b668b |
| plan14-root-reads-sec-unit-app-demobuild.tsv fea6bec1f00dace47aa6006bf8606602efda4cecfa4fe3c3890136c0fb27720c |
| +plan14-root-reads-audit-request-path.tsv 3f7dc37d114377b168c6bc1ae48e7bf815dbc1f5a569274af642e00e7d08ca2a |