audit-request-path: Astra round 1 P2 fixes
P2-1: upstreamDialer's comment said multiProxy and the prober both bound their dials with a context deadline. Only multiProxy does (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. The comment now says so and marks bounding it as follow-up work; the prober itself is unchanged here. (Commit c6ec153f's message makes the same wrong claim; this corrects the record.) P2-2: TestHealthWaitStopsProbingWhenCancelled took its probe baseline after a 100 ms settling sleep, so on a loaded runner a probe already sent could land after it and fail the test. The wake is now cancelled from inside the second probe's handler: the wait sends one probe at a time, so that probe is the only one in flight and is already counted, and any later start is a new probe. The test asserts the count stays at 2 across six poll intervals. Still fails on the old code (6 new probes). Census: upstreamdial.go is in scope; census-propose re-run with the same NAME re-pins the internal/edge envelope. No unit changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+29
−18
internal/activator/healthwait_cancel_test.go+22 −15internal/edge/upstreamdial.go+6 −2internal/provision/testdata/plan14-root-reads-audit-request-path.tsv+1 −1
CI cancelled — superseded by a newer push — run details
diff --git a/internal/activator/healthwait_cancel_test.go b/internal/activator/healthwait_cancel_test.go| index ca51e2e31..7f0bbdaf2 100644 |
| --- a/internal/activator/healthwait_cancel_test.go |
| +++ b/internal/activator/healthwait_cancel_test.go |
| @@ -52,14 +52,19 @@ func runWait(ctx context.Context, wait func(context.Context) error) <-chan error |
| } |
| 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(time.Second): |
| - t.Fatal("the wait did not return within 1s of its context ending") |
| + case <-time.After(d): |
| + t.Fatalf("the wait did not return within %v", d) |
| } |
| } |
| @@ -70,25 +75,27 @@ func wantCanceled(t *testing.T, done <-chan error) { |
| 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) { |
| - probes.Add(1) |
| + if probes.Add(1) == cancelAt { |
| + cancel() |
| + } |
| w.WriteHeader(http.StatusServiceUnavailable) |
| })) |
| - ctx, cancel := context.WithCancel(context.Background()) |
| - defer cancel() |
| done := runWait(ctx, wait) |
| - waitFor(t, "two probes", func() bool { return probes.Load() >= 2 }) |
| - cancel() |
| - wantCanceled(t, done) |
| - // A probe already on the wire may still reach the handler just |
| - // after the return; let it land, then expect silence across |
| - // several poll intervals (healthPollMax is 50 ms). |
| - time.Sleep(100 * time.Millisecond) |
| - n := probes.Load() |
| + 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 != n { |
| - t.Fatalf("%d probes after the wait returned; a cancelled wait must stop probing", got-n) |
| + if got := probes.Load(); got != cancelAt { |
| + t.Fatalf("%d probes started after the cancel; a cancelled wait must stop probing", got-cancelAt) |
| } |
| }) |
| } |
diff --git a/internal/edge/upstreamdial.go b/internal/edge/upstreamdial.go| index dfd4d778a..c9b081407 100644 |
| --- a/internal/edge/upstreamdial.go |
| +++ b/internal/edge/upstreamdial.go |
| @@ -11,8 +11,12 @@ import ( |
| // (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. multiProxy and the prober |
| -// use it (each bounds its dials with a context deadline); tcpProxy uses |
| -// tcpUpstreamDialer; unix sockets, backhaul hops and tunnels use neither. |
| +// 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{}) |
| } |
diff --git a/internal/provision/testdata/plan14-root-reads-audit-request-path.tsv b/internal/provision/testdata/plan14-root-reads-audit-request-path.tsv| index cb3a337f5..0012900d8 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-audit-request-path.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-audit-request-path.tsv |
| @@ -8,4 +8,4 @@ internal/edge/door.go Edge.openDoor legacy accepted-legacy accepted-legacy;rev3= |
| 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 4da43bb754f06142cb2a2a1ef44b42b9cad7945ae34a13a171de44684c6fbf06 |
| +@coverage internal/edge c7041387d997edeea3b2dad2a51bda009c9c0767888ad50af879d1a638a94ee1 |