carlos / platform Public

activator: log listener admission stops at its limit

Astra's census review of this branch (round 1, P2) found that the
connection counter added in f0ec79c9 counted refused connections too.
An atomic.Int32 incremented on every Accept turns negative after 2^31
connections and admits again, which also weakened the systemd
listener's old one-connection refusal.

The accept loop is the only goroutine that touches the count, so it is
now a plain int that grows only when a connection is admitted (admit).
It stops at the limit and no number of refused connections can move it.
TestLogListenerAdmissionStaysExhausted pins that for both listeners.

Census overlay gvisor-empty-execstart re-proposed: the activator
envelope is re-pinned; prepareKeyedAt is unchanged since f0ec79c9.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev b67319dea32c09acff9884e6ef67d417225aeef4 parent f0ec79c
3 files changed, +54 −10
  • internal/activator/gvisor_log_socket_test.go +28 −0
  • internal/activator/loglistener.go +25 −9
  • internal/provision/testdata/plan14-root-reads-gvisor-empty-execstart.tsv +1 −1

CI failed — run details

diff --git a/internal/activator/gvisor_log_socket_test.go b/internal/activator/gvisor_log_socket_test.go
index e2359ed51..9ca393ada 100644
--- a/internal/activator/gvisor_log_socket_test.go
+++ b/internal/activator/gvisor_log_socket_test.go
@@ -157,3 +157,31 @@ func isTimeout(err error) bool {
ne, ok := err.(net.Error)
return ok && ne.Timeout()
}
+
+// Admission stops at its limit and stays stopped: a refused connection
+// never moves the count, so no number of connections can wrap it back
+// under the limit (Astra census review of gvisor-empty-execstart, P2: an
+// int32 counted every connection and turned negative after 2^31).
+func TestLogListenerAdmissionStaysExhausted(t *testing.T) {
+ t.Parallel()
+ for _, tc := range []struct {
+ name string
+ each bool
+ limit int
+ }{{"listenLogs", false, 1}, {"listenLogsEach", true, logEachMax}} {
+ l := &logListener{each: tc.each}
+ for i := 0; i < tc.limit; i++ {
+ if !l.admit() {
+ t.Fatalf("%s: connection %d refused, want admitted up to %d", tc.name, i+1, tc.limit)
+ }
+ }
+ for i := 0; i < 1_000_000; i++ {
+ if l.admit() {
+ t.Fatalf("%s: connection %d admitted after the limit %d", tc.name, tc.limit+i+1, tc.limit)
+ }
+ }
+ if l.admitted != tc.limit {
+ t.Fatalf("%s: admitted = %d after refusals, want it held at %d", tc.name, l.admitted, tc.limit)
+ }
+ }
+}
diff --git a/internal/activator/loglistener.go b/internal/activator/loglistener.go
index 0d0df76b9..910025847 100644
--- a/internal/activator/loglistener.go
+++ b/internal/activator/loglistener.go
@@ -36,10 +36,14 @@ import (
// EOF ends a connection's log collection and nothing else: it is never a
// sign the process is gone (codex R1-4).
type logListener struct {
- ln net.Listener
- emit func(string)
- each bool // tee every connection, up to logEachMax (listenLogsEach)
- accepted atomic.Int32
+ ln net.Listener
+ emit func(string)
+ each bool // tee every connection, up to logEachMax (listenLogsEach)
+ // admitted counts the connections given a tee. Only the accept loop
+ // touches it, and it grows only on admission, so it stops at the limit
+ // and a refused connection can never wrap it back under (Astra census
+ // review of gvisor-empty-execstart, P2).
+ admitted int
closed atomic.Bool
// conns are the accepted connections, kept so Close can shut them and
// unblock their tees; wg covers the accept loop and the tees.
@@ -79,16 +83,12 @@ func listenLogsMode(path string, emit func(string), each bool) (*logListener, er
func (l *logListener) accept() {
defer l.wg.Done()
- limit := int32(1)
- if l.each {
- limit = logEachMax
- }
for {
c, err := l.ln.Accept()
if err != nil {
return
}
- if l.accepted.Add(1) > limit {
+ if !l.admit() {
c.Close()
continue
}
@@ -106,6 +106,22 @@ func (l *logListener) accept() {
}
}
+// admit reports whether the next connection gets a tee: the first only for
+// listenLogs, up to logEachMax for listenLogsEach. Once the limit is reached
+// every later call refuses, however many connections arrive. Called only
+// from the accept loop.
+func (l *logListener) admit() bool {
+ limit := 1
+ if l.each {
+ limit = logEachMax
+ }
+ if l.admitted >= limit {
+ return false
+ }
+ l.admitted++
+ return true
+}
+
func (l *logListener) tee(c net.Conn) {
defer l.wg.Done()
defer c.Close()
diff --git a/internal/provision/testdata/plan14-root-reads-gvisor-empty-execstart.tsv b/internal/provision/testdata/plan14-root-reads-gvisor-empty-execstart.tsv
index 0e93339e3..8deeafd30 100644
--- a/internal/provision/testdata/plan14-root-reads-gvisor-empty-execstart.tsv
+++ b/internal/provision/testdata/plan14-root-reads-gvisor-empty-execstart.tsv
@@ -2,4 +2,4 @@
# 1 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
@legacy 84cd5fce6e3086c742e0a11047129b1a0d671f4b58b62c58a5290ec3b56bf7f3 internal/activator/prepare.go ExecBackend.prepareKeyedAt legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=Re-digested at the pre-land merge: the body includes main's own change under census ruling zddr4, with no further change from this branch beyond carrying main's new early return into the six-value signature. the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): body of the frozen prepareAt, which is now its wrapper; it also returns the instance key's layer and reads no env for the cmd role; same reads, same nested launch paths;rev3=census-ruling-wake-latency-2;basis=takes an optional timer and marks its steps with time.Now() (dirs, admin token, instance key, env, control socket, key gate, logs); no read added or moved;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos, run and seed roles only, under a 30 s context (haSecretsBudget): the token producer is ensureAdminTokenFor(hctx, rt, p) (on this nested path the same beneath producer, EnsureAdminTokenBeneath's, plus the HA mint decision inside it); ensureInstanceKeyFor now gets hctx instead of context.Background(), so the key's bucket read is bounded by 30 s as well as configReadTimeout; the env is launchEnvLayer(hctx, rt) (instanceEnvLayer for a non-HA host; for an HA host one capture, published and acknowledged); a test seam (haLaunchHooks.afterGate, nil in production) is called before the producers. The separate haMintGate and haSecretsReady calls are gone (final fix F2). Sites against main: -registry:Host (the rt.Host+".env" argument EnsureAdminTokenBeneath took) and +whole:Route (rt to launchEnvLayer); the cmd role and a non-HA host are unchanged;rev3=census-ruling-rootfs-fleet-followups;basis=names the process for the role log listener: release.ProcessWeb when rt.Rootfs() and the role is run, else none, passed to logEmitter; reads rt.Runtime through Rootfs(); no file, path or env read added or moved;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 8: the cmd role three exceptions (no env read, the replica gate left to StartCmd, no app-log listener) now cover every one-shot role, instancectl.OneShot(role): cmd and tty; before, the tty role fell to the sidecar env-file read and an app-log listener on its handoff socket path; no read added, one removed for tty;rev3=census-ruling-region-ha-p1b3b-s;basis=Native sidecar run units use the existing nested secrets preparation and acknowledged sealed publication, but bind no app control listener. Existing run and seed reads unchanged.;rev3=census-ruling-gvisor-empty-execstart;basis=on a gVisor box (b.SandboxEffective == execsandbox.EffectiveGVisor, set by Configure at agent startup) the run role's log listener is listenLogsEach, which tees every connection of the invocation (bounded at 8) instead of only the first: the gVisor run unit's ExecStartPre=-runsc delete connects to the same StandardOutput=file: socket before ExecStart, so the one-connection listener refused the main runsc run's connection and the guest died of SIGPIPE on its first log write. Same socket path, same agent-owned listener, same emitter; no file, path or env read added or moved; the systemd family keeps listenLogs file:ReadDir@2965,registry:Host@1783,registry:Host@1995,registry:Host@612,registry:Host@6210,registry:Host@6408,whole:Route@1674,whole:Route@1885,whole:Route@2116,whole:Route@320,whole:Route@4697,whole:Route@5246,whole:Route@6244 3e03d8a191021a908b5bbbd8c65ab4d673ccd487239f9fe1700c974783a5e188
internal/activator/prepare.go ExecBackend.prepareKeyedAt legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=Re-digested at the pre-land merge: the body includes main's own change under census ruling zddr4, with no further change from this branch beyond carrying main's new early return into the six-value signature. the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): body of the frozen prepareAt, which is now its wrapper; it also returns the instance key's layer and reads no env for the cmd role; same reads, same nested launch paths;rev3=census-ruling-wake-latency-2;basis=takes an optional timer and marks its steps with time.Now() (dirs, admin token, instance key, env, control socket, key gate, logs); no read added or moved;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos, run and seed roles only, under a 30 s context (haSecretsBudget): the token producer is ensureAdminTokenFor(hctx, rt, p) (on this nested path the same beneath producer, EnsureAdminTokenBeneath's, plus the HA mint decision inside it); ensureInstanceKeyFor now gets hctx instead of context.Background(), so the key's bucket read is bounded by 30 s as well as configReadTimeout; the env is launchEnvLayer(hctx, rt) (instanceEnvLayer for a non-HA host; for an HA host one capture, published and acknowledged); a test seam (haLaunchHooks.afterGate, nil in production) is called before the producers. The separate haMintGate and haSecretsReady calls are gone (final fix F2). Sites against main: -registry:Host (the rt.Host+".env" argument EnsureAdminTokenBeneath took) and +whole:Route (rt to launchEnvLayer); the cmd role and a non-HA host are unchanged;rev3=census-ruling-rootfs-fleet-followups;basis=names the process for the role log listener: release.ProcessWeb when rt.Rootfs() and the role is run, else none, passed to logEmitter; reads rt.Runtime through Rootfs(); no file, path or env read added or moved;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 8: the cmd role three exceptions (no env read, the replica gate left to StartCmd, no app-log listener) now cover every one-shot role, instancectl.OneShot(role): cmd and tty; before, the tty role fell to the sidecar env-file read and an app-log listener on its handoff socket path; no read added, one removed for tty;rev3=census-ruling-region-ha-p1b3b-s;basis=Native sidecar run units use the existing nested secrets preparation and acknowledged sealed publication, but bind no app control listener. Existing run and seed reads unchanged.;rev3=census-ruling-gvisor-empty-execstart;basis=on a gVisor box (b.SandboxEffective == execsandbox.EffectiveGVisor, set by Configure at agent startup) the run role's log listener is listenLogsEach, which tees every connection of the invocation (bounded at 8) instead of only the first: the gVisor run unit's ExecStartPre=-runsc delete connects to the same StandardOutput=file: socket before ExecStart, so the one-connection listener refused the main runsc run's connection and the guest died of SIGPIPE on its first log write. Same socket path, same agent-owned listener, same emitter; no file, path or env read added or moved; the systemd family keeps listenLogs file:ReadDir@2965,registry:Host@1783,registry:Host@1995,registry:Host@612,registry:Host@6210,registry:Host@6408,whole:Route@1674,whole:Route@1885,whole:Route@2116,whole:Route@320,whole:Route@4697,whole:Route@5246,whole:Route@6244 3e03d8a191021a908b5bbbd8c65ab4d673ccd487239f9fe1700c974783a5e188
-@coverage internal/activator 094db9a04dc50fc01ba192856eb18b28a326efa7bb82b8c4f537336840278479
+@coverage internal/activator 42c9b9c52ad6a36fc806a2a2ff35925cf404668c9c4d33d8f6145b4452e14f00