carlos / platform Public

Region HA dead-holder backoff, round 2 (final) fixes: the dial bound enforced centrally (Paul's ruling under stopping rule 2, after Astra's re-review of 28fc3b90 found P2-1 and P2-2 not addressed; P2-3 addressed and the census approved). The edge's forward transport, one per holder address, now dials through a forwardDialGate: at most one TCP dial to a holder is in flight. Dials that arrive meanwhile wait for its outcome within their own forwardDialTimeout; a failure answers every waiter at once with its error, and every dial that arrives until the failed dial's forwardDialTimeout has run out, so a box that refuses at once costs no more dials than one that does not answer; a success lets each waiter dial its own connection. The dial in flight is detached from its caller's cancellation, so a visitor hanging up does not fail the others. Each failed forward reports ForwardUnreachable and the cache's generation rule lands one of them. The bound holds whatever the cache believes (cold entry, live entry after a success, idle pool dropped), so round 1's cache-level connection gate, NoteConnected and the GotConn hook are removed as redundant, with their tests. P2-2: a forward that answers while a suspect's revalidation read runs (no entry in the cache) makes the box that answered the holder and invalidates the read, so its failure no longer renews the suspicion; it sets nothing when no read is in flight or when this box taking the lease (a drop) already invalidated it. Guard test TestDeadHolderGuardRealWiring (package edge_test, the real activator Service over an ExecBackend and the lock fixture, through the real edge scene via forwardha_export_test.go): the holder serves one forward; then its listener is closed, its connections cut and annie's idle forward connections dropped while its lease and the cache entry stay live; 20 concurrent requests make exactly one dial (counted at the dial seam) and get 20 x 503 Retry-After: 10, both with the dial refused at once and black-holed; then sequential requests within 10 s make no dial and no lock read. Also TestForwardDialGate, TestSuccessDuringRevalidationWins (success; lease acquisition first), TestSuspectWindowEndReadsOnce (20 failures under one generation land once), TestForwardHANoteCarriesTheGen. N-HA10 kept, 50,000 bound kept, no new copy, no new S3 request. Census re-proposed under the same NAME: Edge.frontForwardHA body only, read sites unchanged; activator and edge envelopes re-pinned. Not released.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev c88f58a90a4208de366c595f9314a9888ce0542c parent 28fc3b9
13 files changed, +557 −415
  • docs/superpowers/notes/census-proposal-region-ha-dead-holder-backoff.md +3 −3
  • docs/superpowers/notes/census-region-ha-dead-holder-backoff-claims.md +3 −3
  • internal/activator/hacache.go +62 −183
  • internal/activator/haforward.go +1 −11
  • internal/activator/haforward_test.go +1 −10
  • internal/activator/hasuspect_test.go +82 −113
  • internal/edge/backhaul_e2e_test.go +3 −0
  • internal/edge/forwardha.go +77 −32
  • internal/edge/forwardha_export_test.go +76 −0
  • internal/edge/forwardha_test.go +136 −53
  • internal/edge/forwardha_wiring_test.go +106 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −1
  • internal/provision/testdata/plan14-root-reads-region-ha-dead-holder-backoff.tsv +6 −6

CI passed — run details

Intent

Human

<task-notification> <task-id>b1a1zbipb</task-id> <tool-use-id>toolu_01HCy9MHHaC94qxPaKA6pvvr</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/953e7524-2e06-4308-b9ce-fd1b38579971/tasks/b1a1zbipb.output</output-file> <status>completed</status> <summary>Background command "Wait for usage flushes, then read per-box usage" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>byopsca6t</task-id> <tool-use-id>toolu_01YL4ZeDMnJEt9E5b2aHgTXT</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/953e7524-2e06-4308-b9ce-fd1b38579971/tasks/byopsca6t.output</output-file> <status>completed</status> <summary>Background command "Wait 5 minutes then read per-box usage" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>bpif4fpnq</task-id> <tool-use-id>toolu_01GJz6VBUgU9y5JneVHpT3yH</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/953e7524-2e06-4308-b9ce-fd1b38579971/tasks/bpif4fpnq.output</output-file> <status>completed</status> <summary>Background command "Wait for 200s to resume through sophie after lease expiry" completed (exit code 0)</summary> </task-notification>

diff --git a/docs/superpowers/notes/census-proposal-region-ha-dead-holder-backoff.md b/docs/superpowers/notes/census-proposal-region-ha-dead-holder-backoff.md
index c71b02ec9..7c6dc3b24 100644
--- a/docs/superpowers/notes/census-proposal-region-ha-dead-holder-backoff.md
+++ b/docs/superpowers/notes/census-proposal-region-ha-dead-holder-backoff.md
@@ -4,8 +4,8 @@ Ruling `census-ruling-region-ha-dead-holder-backoff`. The independent reviewer a
| unit | change | read sites | what changed |
|---|---|---|---|
-| `internal/edge/forwardha.go` `Edge.frontForwardHA` | body | unchanged (5) | ForwardTarget returns a ForwardDecision (Ref, Refuse, Gen); a Refuse is answered at the front door with the existing unreachable answer (503, Retry-After: 10, same body, via answerHolderUnreachable), with no forward, dial, note or per-request step. A forward now passes the decision to forwardHA with a callback that calls the activator's NoteConnected(route host, Gen) once when the transport has the connection (httptrace GotConn), and NoteForward carries Ref and Gen back. The route host is read once into a local; the same 5 read sites; no new read; root never calls it. |
-| `internal/activator/haforward.go` `Service.ForwardTarget` | sites | -registry:Host | Returns edge.ForwardDecision (Ref, Refuse, Gen) from holderCache.resolve, which is in memory only: a suspect holder refuses; a positive entry with no confirmed connection lets one request dial and the rest wait (bounded) on its connection; a failed read that revalidates an expired suspect keeps it suspect and refuses. The same single bounded (2 s) lock.json read through readHolderView on a miss; no new read and no new S3 request; root never calls it. |
+| `internal/edge/forwardha.go` `Edge.frontForwardHA` | body | unchanged (5) | ForwardTarget returns a ForwardDecision (Ref, Refuse, Gen); a Refuse is answered at the front door with the existing unreachable answer (503, Retry-After: 10, same body, via answerHolderUnreachable), with no forward, dial, note or per-request step. A forward passes the decision to forwardHA and NoteForward carries Ref and Gen back. The round-1 connection callback (NoteConnected) is gone: the dial bound now lives in forwardTransport's forwardDialGate, which coalesces TCP dials per holder address in memory. The same 5 read sites; no new read; root never calls it. |
+| `internal/activator/haforward.go` `Service.ForwardTarget` | sites | -registry:Host | Returns edge.ForwardDecision (Ref, Refuse, Gen) from holderCache.resolve, in memory only: a suspect holder refuses; a positive entry forwards under its generation; a failed read that revalidates an expired suspect keeps it suspect and refuses. The round-1 cache connection gate is removed. The same single bounded (2 s) lock.json read through readHolderView on a miss; no new read and no new S3 request; root never calls it. |
Envelopes re-pinned: `internal/activator`, `internal/edge`.
@@ -16,6 +16,6 @@ Recorded dispositions, which each change must still satisfy:
- `internal/edge/forwardha.go` `Edge.frontForwardHA`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-region-ha-p1b2;basis=new (region HA P1b-2): the agent's edge decides at the front door whether to forward a visitor request: reads the route's HA flag and host from the box's own registry row and asks the activator; forwards only to a box in view over the existing signed hop; root never calls it
- `internal/activator/haforward.go` `Service.ForwardTarget`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-region-ha-p1b2;basis=new (region HA P1b-2): the agent's activator answers the edge with a holder box ref for an HA route not awake here, from its in-memory holder cache or one bounded (2 s) lock.json read through readHolderView; reads the route's HA flag and host from its own registry row; root never calls it
-Seal: `5b559ba7a42084908cb0fec08083bb2b9b3c9d960036fd10418f81e56304bb64` โ†’ `61dc010abf76d6f3a17f9b376935d8c440f53a32ca866923c55a6069ca1dc343`.
+Seal: `5b559ba7a42084908cb0fec08083bb2b9b3c9d960036fd10418f81e56304bb64` โ†’ `8f6a1865b0abcea9d4fb68232cc2a25263a106ec87f73bd4b3f2fb388971ebe5`.
Overlay: `internal/provision/testdata/plan14-root-reads-region-ha-dead-holder-backoff.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/docs/superpowers/notes/census-region-ha-dead-holder-backoff-claims.md b/docs/superpowers/notes/census-region-ha-dead-holder-backoff-claims.md
index fddda799b..0dae7e6a2 100644
--- a/docs/superpowers/notes/census-region-ha-dead-holder-backoff-claims.md
+++ b/docs/superpowers/notes/census-region-ha-dead-holder-backoff-claims.md
@@ -1,4 +1,4 @@
-# CLAIMS for the root-read census, branch region-ha-dead-holder-backoff (region HA P1b-2 follow-up: dead-holder backoff), round 1 fixes.
+# CLAIMS for the root-read census, branch region-ha-dead-holder-backoff (region HA P1b-2 follow-up: dead-holder backoff), round 2 (final) fixes.
# Format (AGENTS.md "The census"): <file>:<unit><TAB><what changed>. Lines starting with # are ignored.
-internal/edge/forwardha.go:Edge.frontForwardHA ForwardTarget returns a ForwardDecision (Ref, Refuse, Gen); a Refuse is answered at the front door with the existing unreachable answer (503, Retry-After: 10, same body, via answerHolderUnreachable), with no forward, dial, note or per-request step. A forward now passes the decision to forwardHA with a callback that calls the activator's NoteConnected(route host, Gen) once when the transport has the connection (httptrace GotConn), and NoteForward carries Ref and Gen back. The route host is read once into a local; the same 5 read sites; no new read; root never calls it.
-internal/activator/haforward.go:Service.ForwardTarget Returns edge.ForwardDecision (Ref, Refuse, Gen) from holderCache.resolve, which is in memory only: a suspect holder refuses; a positive entry with no confirmed connection lets one request dial and the rest wait (bounded) on its connection; a failed read that revalidates an expired suspect keeps it suspect and refuses. The same single bounded (2 s) lock.json read through readHolderView on a miss; no new read and no new S3 request; root never calls it.
+internal/edge/forwardha.go:Edge.frontForwardHA ForwardTarget returns a ForwardDecision (Ref, Refuse, Gen); a Refuse is answered at the front door with the existing unreachable answer (503, Retry-After: 10, same body, via answerHolderUnreachable), with no forward, dial, note or per-request step. A forward passes the decision to forwardHA and NoteForward carries Ref and Gen back. The round-1 connection callback (NoteConnected) is gone: the dial bound now lives in forwardTransport's forwardDialGate, which coalesces TCP dials per holder address in memory. The same 5 read sites; no new read; root never calls it.
+internal/activator/haforward.go:Service.ForwardTarget Returns edge.ForwardDecision (Ref, Refuse, Gen) from holderCache.resolve, in memory only: a suspect holder refuses; a positive entry forwards under its generation; a failed read that revalidates an expired suspect keeps it suspect and refuses. The round-1 cache connection gate is removed. The same single bounded (2 s) lock.json read through readHolderView on a miss; no new read and no new S3 request; root never calls it.
diff --git a/internal/activator/hacache.go b/internal/activator/hacache.go
index edc3c31ab..520e1b923 100644
--- a/internal/activator/hacache.go
+++ b/internal/activator/hacache.go
@@ -5,8 +5,6 @@ import (
"context"
"sync"
"time"
-
- "github.com/carlosframework/platform/internal/edge"
)
// The holder cache (region HA P1b-2; spec 2026-10-26 ยง6.6): for a born-HA
@@ -16,10 +14,11 @@ import (
// here" and exists only to cap the lock reads of a host that keeps
// missing. A suspect one names a holder that did not answer a forward: the
// host's requests are refused until it expires, and the request after that
-// reads the lock again. A positive entry's first connection is made by one
-// request at a time (its gate); the rest wait for it. Every entry carries
-// a generation, handed out with each forward and renewed by each change,
-// so an outcome older than the cache's news is ignored. The cache is
+// reads the lock again. Every entry carries a generation, handed out with
+// each forward and renewed by each change, so an outcome older than the
+// cache's news is ignored. (How many dials a dead holder costs is bounded
+// where the dials are made, in the edge's forward transport:
+// forwardDialGate.) The cache is
// advice, never a lease: every way it can be wrong ends in a drop
// (haforward.go's NoteForward, the acquire in doWake) or, at the latest,
// its lifetime.
@@ -37,12 +36,6 @@ const (
// no lock read and no dial, so a dead holder whose lease has not run
// out costs one lock read and one failed dial per host per 10 s per box.
holderSuspectTTL = 10 * time.Second
- // holderConnectWait bounds a request's wait on another request's first
- // connection to a holder: the edge's own dial bound, TCP and TLS, plus
- // the hop's set-up before it dials. A first connection that has not
- // reported by then is abandoned: its waiters are refused, and the next
- // request dials.
- holderConnectWait = edge.ForwardDialTimeout + 500*time.Millisecond
)
// holderCache is host to holder box reference. The zero value is ready;
@@ -61,23 +54,9 @@ type holderEntry struct {
ref string // "" for a negative entry
suspect bool // ref did not answer a forward
expires time.Time
- // gen is the entry's generation: new with every put, and with every
- // first connection attempt. A forward's outcome counts only under it.
+ // gen is the entry's generation, new with every put and every answer
+ // from ref: a forward's failure counts only under it.
gen uint64
- // confirmed: a forward under gen connected to ref, or ref answered.
- confirmed bool
- // gate is the first connection to ref in flight, nil for none.
- gate *holderGate
-}
-
-// holderGate is a positive entry's first connection attempt. Requests that
-// find it wait for done, closed when the attempt connected, failed, ended
-// without connecting, or the entry changed; here is set when the entry was
-// removed, and its waiters are served here as the attempt was.
-type holderGate struct {
- done chan struct{}
- since time.Time
- here bool
}
// holderFlight is one lock read in flight for a host. stale is set when
@@ -139,60 +118,30 @@ func (c *holderCache) setNegative(host string) {
c.putLocked(host, "", false, holderNegativeTTL)
}
-// liveLocked is host's positive entry when it is still at gen: the entry
-// a forward under gen was decided from, unchanged since. Generations are
-// never reused, so gen also names the box.
-func (c *holderCache) liveLocked(host string, gen uint64) *holderEntry {
- el := c.holders[host]
- if el == nil || gen == 0 {
- return nil
- }
- e := el.Value.(*holderEntry)
- if e.gen != gen || e.ref == "" || e.suspect {
- return nil
- }
- return e
-}
-
// unreachable follows a forward under gen that could not connect: its box
-// is suspect for holderSuspectTTL, and the waiters on its first connection
-// are refused. An outcome under an older generation is ignored: the entry
-// has changed since (a success, a holder header, a drop), or it is suspect
-// already.
+// is suspect for holderSuspectTTL. An outcome under an older generation is
+// ignored: the entry has changed since (a success, a holder header, a
+// drop), or it is suspect already, so of many forwards failing together
+// one lands. Generations are never reused, so gen also names the box.
func (c *holderCache) unreachable(host string, gen uint64) {
c.mu.Lock()
defer c.mu.Unlock()
- if e := c.liveLocked(host, gen); e != nil {
- c.putLocked(host, e.ref, true, holderSuspectTTL)
- }
-}
-
-// connected follows a forward under gen that connected: its box's
-// connection is confirmed, and the waiters on its first connection forward.
-func (c *holderCache) connected(host string, gen uint64) {
- c.mu.Lock()
- defer c.mu.Unlock()
- if e := c.liveLocked(host, gen); e != nil {
- e.confirmed = true
- e.releaseGate(false)
+ el := c.holders[host]
+ if el == nil || gen == 0 {
+ return
}
-}
-
-// unconnected follows a forward under gen that ended without connecting or
-// failing to (the hop was refused here): the next request makes the first
-// connection.
-func (c *holderCache) unconnected(host string, gen uint64) {
- c.mu.Lock()
- defer c.mu.Unlock()
- if e := c.liveLocked(host, gen); e != nil && !e.confirmed {
- e.releaseGate(false)
+ if e := el.Value.(*holderEntry); e.gen == gen && e.ref != "" && !e.suspect {
+ c.putLocked(host, e.ref, true, holderSuspectTTL)
}
}
// answered follows a forward of host's to ref that came back with an
// answer: ref is reachable. A suspect entry is replaced by ref as the
-// holder, confirmed; an entry naming ref is confirmed under a new
-// generation, so older failures no longer count. Any other entry stands.
+// holder; an entry naming ref gets a new generation, so older failures no
+// longer count. With no entry, a read revalidating an expired suspect is
+// overtaken: ref is the holder, and the read's answer is not cached. Any
+// other entry stands, and nothing is set when no read is in flight: a
+// drop (this box taking the lease, a holder saying none) is not undone.
func (c *holderCache) answered(host, ref string) {
if ref == "" {
return
@@ -201,20 +150,19 @@ func (c *holderCache) answered(host, ref string) {
defer c.mu.Unlock()
el := c.holders[host]
if el == nil {
+ if f := c.flights[host]; f != nil && f.suspect != "" && !f.stale {
+ c.putLocked(host, ref, false, holderPositiveTTL)
+ }
return
}
e := el.Value.(*holderEntry)
- if !e.suspect && e.ref != ref {
- return
- }
- if e.suspect {
- e = c.putLocked(host, ref, false, holderPositiveTTL)
- } else {
+ switch {
+ case e.suspect:
+ c.putLocked(host, ref, false, holderPositiveTTL)
+ case e.ref == ref:
c.seq++
e.gen = c.seq
- e.releaseGate(false)
}
- e.confirmed = true
}
// drop forgets host's entry, and any read in flight for it.
@@ -229,9 +177,8 @@ func (c *holderCache) drop(host string) {
}
}
-// putLocked sets host's entry under a new generation, unconfirmed, and
-// releases any waiters on its old gate to look again.
-func (c *holderCache) putLocked(host, ref string, suspect bool, ttl time.Duration) *holderEntry {
+// putLocked sets host's entry under a new generation.
+func (c *holderCache) putLocked(host, ref string, suspect bool, ttl time.Duration) {
if f := c.flights[host]; f != nil {
f.stale = true
}
@@ -242,131 +189,80 @@ func (c *holderCache) putLocked(host, ref string, suspect bool, ttl time.Duratio
expires := c.clock().Add(ttl)
if el := c.holders[host]; el != nil {
e := el.Value.(*holderEntry)
- e.releaseGate(false)
- e.ref, e.suspect, e.expires, e.gen, e.confirmed = ref, suspect, expires, c.seq, false
+ e.ref, e.suspect, e.expires, e.gen = ref, suspect, expires, c.seq
c.order.MoveToBack(el)
- return e
+ return
}
for len(c.holders) >= holderCacheMax {
c.removeLocked(c.order.Front())
}
- e := &holderEntry{host: host, ref: ref, suspect: suspect, expires: expires, gen: c.seq}
- c.holders[host] = c.order.PushBack(e)
- return e
+ c.holders[host] = c.order.PushBack(&holderEntry{host: host, ref: ref, suspect: suspect, expires: expires, gen: c.seq})
}
func (c *holderCache) removeLocked(el *list.Element) {
- e := el.Value.(*holderEntry)
- e.releaseGate(true)
- delete(c.holders, e.host)
+ delete(c.holders, el.Value.(*holderEntry).host)
c.order.Remove(el)
}
-// releaseGate ends e's first connection attempt, if any, waking its
-// waiters; here sends them to be served here.
-func (e *holderEntry) releaseGate(here bool) {
- if g := e.gate; g != nil {
- g.here = here
- close(g.done)
- e.gate = nil
- }
-}
-
// resolve answers a request for host: the holder to forward to and the
-// generation to report its outcome under, "" to serve here, or refuse.
-//
-// - A suspect entry refuses; a negative one serves here.
-// - A positive entry with a confirmed connection forwards. Without one,
-// the request that finds no gate opens one and forwards: it makes the
-// first connection. Requests that find the gate wait on it, until it
-// connects (they forward), fails (they are refused, the box being
-// suspect), or the entry changes (they look again); a gate older than
-// holderConnectWait is abandoned, and the next request opens another.
-// - A miss is one read at a time: the first caller runs read and every
-// caller meanwhile waits for its answer (or its own ctx, answering
-// ""). read names the holder ("" for none) and ok false when it could
-// not tell, which caches nothing. A read that replaces an expired
-// suspect entry and fails keeps the box suspect for another window and
-// refuses its callers.
-//
-// Every wait, and so the whole answer, is bounded: past the read's own
-// timeout and one connection wait, the request is refused.
+// generation to report its outcome under, "" to serve here, or refuse
+// while the holder is suspect. A live entry answers at once. A miss is one
+// read at a time: the first caller runs read and every caller meanwhile
+// waits for its answer (or its own ctx, answering ""). read names the
+// holder ("" for none) and ok false when it could not tell, which caches
+// nothing. A read that replaces an expired suspect entry and fails keeps
+// the box suspect for another window and refuses its callers; a read
+// overtaken by news sends its callers to look again, within twice the
+// read's timeout in all.
func (c *holderCache) resolve(ctx context.Context, host string, read func() (ref string, ok bool)) (string, bool, uint64) {
- deadline := time.Now().Add(holderReadTimeout + holderConnectWait)
+ deadline := time.Now().Add(2 * holderReadTimeout)
for time.Now().Before(deadline) {
c.mu.Lock()
suspect := ""
if el := c.holders[host]; el != nil {
e := el.Value.(*holderEntry)
- now := c.clock()
- if now.Before(e.expires) {
- switch {
- case e.suspect:
- c.mu.Unlock()
- return "", true, 0
- case e.ref == "":
- c.mu.Unlock()
- return "", false, 0
- case e.confirmed:
- ref, gen := e.ref, e.gen
- c.mu.Unlock()
- return ref, false, gen
- case e.gate == nil || !now.Before(e.gate.since.Add(holderConnectWait)):
- e.releaseGate(false)
- c.seq++
- e.gen = c.seq
- e.gate = &holderGate{done: make(chan struct{}), since: now}
- ref, gen := e.ref, e.gen
- c.mu.Unlock()
- return ref, false, gen
- }
- g := e.gate
- wait := min(g.since.Add(holderConnectWait).Sub(now), time.Until(deadline))
+ if c.clock().Before(e.expires) {
+ ref, refuse, gen := e.ref, e.suspect, e.gen
c.mu.Unlock()
- if !waitGate(ctx, g, wait) {
+ if refuse {
return "", true, 0
}
- if g.here {
+ if ref == "" {
return "", false, 0
}
- continue
+ return ref, false, gen
}
if e.suspect {
suspect = e.ref
}
c.removeLocked(el)
}
- if f := c.flights[host]; f != nil {
+ f := c.flights[host]
+ if f != nil {
c.mu.Unlock()
select {
case <-f.done:
case <-ctx.Done():
return "", false, 0
}
- if f.refuse {
- return "", true, 0
- }
- if f.cached || f.stale {
- continue
+ } else {
+ f = &holderFlight{done: make(chan struct{}), suspect: suspect}
+ if c.flights == nil {
+ c.flights = map[string]*holderFlight{}
}
- return f.ref, false, 0
- }
- f := &holderFlight{done: make(chan struct{}), suspect: suspect}
- if c.flights == nil {
- c.flights = map[string]*holderFlight{}
+ c.flights[host] = f
+ c.mu.Unlock()
+ c.runRead(host, f, read)
}
- c.flights[host] = f
- c.mu.Unlock()
- c.runRead(host, f, read)
- if f.refuse {
+ switch {
+ case f.refuse:
return "", true, 0
- }
- if f.cached || f.stale {
+ case f.cached, f.stale:
continue
}
return f.ref, false, 0
}
- return "", true, 0
+ return "", false, 0
}
// runRead runs f's read for host and settles f: its answer cached, unless
@@ -398,20 +294,3 @@ func (c *holderCache) runRead(host string, f *holderFlight, read func() (string,
}()
ref, ok = read()
}
-
-// waitGate waits up to d for g; false when d or ctx ran out first.
-func waitGate(ctx context.Context, g *holderGate, d time.Duration) bool {
- if d <= 0 {
- return false
- }
- t := time.NewTimer(d)
- defer t.Stop()
- select {
- case <-g.done:
- return true
- case <-t.C:
- return false
- case <-ctx.Done():
- return false
- }
-}
diff --git a/internal/activator/haforward.go b/internal/activator/haforward.go
index dbad6b014..9d0240102 100644
--- a/internal/activator/haforward.go
+++ b/internal/activator/haforward.go
@@ -160,8 +160,7 @@ func otherHolder(v hafresh.View, self string, now time.Time) string {
// (this box is never forwarded to). A box that could not be connected to
// is suspect for holderSuspectTTL, unless the forward's generation is
// older than the entry's; any other answer from a box clears a suspect
-// entry: that box is the holder. A forward that ended with no answer and
-// no connection lets the next request make the first connection.
+// entry: that box is the holder.
func (a *Service) NoteForward(host string, res edge.ForwardResult) {
switch {
case res.Outcome == edge.ForwardNotInView:
@@ -180,18 +179,9 @@ func (a *Service) NoteForward(host string, res edge.ForwardResult) {
a.holders.drop(host)
case res.Status != 0:
a.holders.answered(host, res.Ref)
- default:
- a.holders.unconnected(host, res.Gen)
}
}
-// NoteConnected follows a forward's connection to its box being made,
-// before any answer: under gen, the box's connection is confirmed and the
-// requests waiting on that first connection forward.
-func (a *Service) NoteConnected(host string, gen uint64) {
- a.holders.connected(host, gen)
-}
-
// answerForwarded is the holder diagnostic on the refusal err of a
// forwarded request (a verified hop) on an HA route; it reports whether it
// wrote the whole answer. A held lease is 503, Retry-After: 1 and the
diff --git a/internal/activator/haforward_test.go b/internal/activator/haforward_test.go
index d840c59c7..d534f9f1c 100644
--- a/internal/activator/haforward_test.go
+++ b/internal/activator/haforward_test.go
@@ -57,7 +57,6 @@ func TestForwardTargetNamesTheHolder(t *testing.T) {
if n := lockGets(s.b, s.rt); n != 1 {
t.Fatalf("%d lock reads on a miss, want 1", n)
}
- s.a.NoteConnected(s.rt.Host, d.Gen)
if got := s.a.ForwardTarget(context.Background(), s.rt).Ref; got != "b" {
t.Fatalf("ForwardTarget on a hit = %q, want b", got)
}
@@ -149,15 +148,8 @@ func TestForwardTargetSingleFlight(t *testing.T) {
waitFor(t, "the first read", func() bool { return reads.Load() == 1 })
time.Sleep(50 * time.Millisecond) // the other 19 queue on it
close(gate)
- // One caller makes the first connection; the rest wait on it.
- first := recv(t, got)
- s.a.NoteConnected(s.rt.Host, first.Gen)
for i := range 20 {
- d := first
- if i > 0 {
- d = recv(t, got)
- }
- if d.Ref != "b" || d.Refuse {
+ if d := recv(t, got); d.Ref != "b" || d.Refuse {
t.Fatalf("caller %d got %+v, want b", i, d)
}
}
@@ -409,7 +401,6 @@ func TestForwardTargetThroughSplitBackend(t *testing.T) {
if n := lockGets(s.b, s.rt); n != 1 {
t.Fatalf("%d lock reads on a miss, want 1", n)
}
- a.NoteConnected(s.rt.Host, d.Gen)
if got := a.ForwardTarget(context.Background(), s.rt).Ref; got != "b" || lockGets(s.b, s.rt) != 1 {
t.Fatalf("a hit: %q with %d reads, want b and 1", got, lockGets(s.b, s.rt))
}
diff --git a/internal/activator/hasuspect_test.go b/internal/activator/hasuspect_test.go
index fab14d1f3..d567d1ab9 100644
--- a/internal/activator/hasuspect_test.go
+++ b/internal/activator/hasuspect_test.go
@@ -15,9 +15,9 @@ import (
// Region HA P1b-2 follow-up: a holder that did not answer a forward is
// suspect for holderSuspectTTL. While it is, a visitor's request for the
// host is refused at the front door with no lock read, no dial and no
-// local wake, and the first connection to a holder is made by one request
-// while the rest wait on it, so a dead holder whose lease has not run out
-// costs each box one lock read and one failed dial per window per host.
+// local wake; with the edge's dial gate (forwardDialGate) a dead holder
+// whose lease has not run out costs each box one lock read and one failed
+// dial per window per host.
// frontDoor is one visitor request for s's host at the edge's front door
// (edge.frontForwardHA), over a forward that never connects. It asks
@@ -64,16 +64,6 @@ func (s *haSvc) concurrently(n int) <-chan edge.ForwardDecision {
return out
}
-// noneYet fails if a decision arrives on ch within 100 ms.
-func noneYet(t *testing.T, ch <-chan edge.ForwardDecision, why string) {
- t.Helper()
- select {
- case d := <-ch:
- t.Fatalf("%s: a request returned %+v, want it waiting", why, d)
- case <-time.After(100 * time.Millisecond):
- }
-}
-
// recv is the next decision on ch, within 10 s.
func recv(t *testing.T, ch <-chan edge.ForwardDecision) edge.ForwardDecision {
t.Helper()
@@ -153,9 +143,10 @@ func TestDeadHolderCostsOneReadAndDialPerWindow(t *testing.T) {
}
}
-// Concurrent requests after the window: one lock read, one forward. The
-// rest wait on that forward's connection and, when it fails, are refused.
-func TestSuspectWindowEndForwardsOnce(t *testing.T) {
+// Concurrent requests after the window: one lock read, and all of them
+// forward to b under one generation (the edge's dial gate makes that one
+// dial). Of their twenty failures one lands: b is suspect once.
+func TestSuspectWindowEndReadsOnce(t *testing.T) {
s, clk := suspectB(t)
clk.advance(holderSuspectTTL + time.Millisecond)
gate := make(chan struct{})
@@ -171,103 +162,27 @@ func TestSuspectWindowEndForwardsOnce(t *testing.T) {
waitFor(t, "the read", func() bool { return reads.Load() == 1 })
time.Sleep(50 * time.Millisecond) // the others queue on it
close(gate)
- first := recv(t, got)
- if first.Ref != "b" || first.Refuse {
- t.Fatalf("the first decision after the read: %+v, want a forward to b", first)
- }
- noneYet(t, got, "before the forward's connection is known")
- s.note(first, edge.ForwardResult{Outcome: edge.ForwardUnreachable})
- for i := range 19 {
- if d := recv(t, got); !d.Refuse {
- t.Fatalf("waiter %d after the forward failed to connect: %+v, want a refusal", i, d)
+ ds := make([]edge.ForwardDecision, 20)
+ for i := range ds {
+ ds[i] = recv(t, got)
+ if ds[i].Ref != "b" || ds[i].Refuse || ds[i].Gen != ds[0].Gen {
+ t.Fatalf("caller %d: %+v, want b under the first caller's gen %d", i, ds[i], ds[0].Gen)
}
}
- if reads.Load() != 1 {
- t.Fatalf("%d reads for 20 requests after the window, want 1", reads.Load())
- }
-}
-
-// The first forward to a holder with no confirmed connection is the only
-// one dialled: concurrent requests wait on its connection. When it
-// connects (before any answer, so a slow app holds nothing) they forward;
-// when it cannot, they are refused, and the holder is suspect.
-func TestFirstDialGatesConcurrentRequests(t *testing.T) {
- t.Run("connects", func(t *testing.T) {
- s := haHeldByB(t)
- got := s.concurrently(20)
- first := recv(t, got)
- if first.Ref != "b" || first.Refuse {
- t.Fatalf("the first decision: %+v, want a forward to b", first)
- }
- noneYet(t, got, "while the first dial is held open")
- dials := 1 // every decision so far that would dial
- s.a.NoteConnected(s.rt.Host, first.Gen)
- for i := range 19 {
- if d := recv(t, got); d.Ref != "b" || d.Refuse {
- t.Fatalf("waiter %d after the connection: %+v, want a forward to b", i, d)
- }
- }
- if dials != 1 || lockGets(s.b, s.rt) != 1 {
- t.Fatalf("%d dials and %d reads while the first dial was open, want 1 and 1", dials, lockGets(s.b, s.rt))
- }
- // A confirmed connection lifts the gate: no request waits.
- if d := s.decide(); d.Ref != "b" {
- t.Fatalf("after the connection: %+v, want b at once", d)
- }
- })
- t.Run("unreachable", func(t *testing.T) {
- s := haHeldByB(t)
- got := s.concurrently(20)
- first := recv(t, got)
- noneYet(t, got, "while the first dial is held open")
- s.note(first, edge.ForwardResult{Outcome: edge.ForwardUnreachable})
- for i := range 19 {
- if d := recv(t, got); !d.Refuse {
- t.Fatalf("waiter %d after the dial failed: %+v, want a refusal", i, d)
- }
- }
- if lockGets(s.b, s.rt) != 1 {
- t.Fatalf("%d reads, want 1", lockGets(s.b, s.rt))
- }
- })
- t.Run("ended without connecting", func(t *testing.T) {
- // The hop was refused here before it dialled (Status 0): the next
- // request dials; the rest go on waiting.
- s := haHeldByB(t)
- got := s.concurrently(5)
- first := recv(t, got)
- s.note(first, edge.ForwardResult{Outcome: edge.ForwardDone})
- second := recv(t, got)
- if second.Ref != "b" || second.Gen == first.Gen {
- t.Fatalf("after a forward that never dialled: %+v, want the next dial (gen %d was the first)", second, first.Gen)
- }
- noneYet(t, got, "while the second dial is held open")
- s.a.NoteConnected(s.rt.Host, second.Gen)
- for range 3 {
- if d := recv(t, got); d.Ref != "b" {
- t.Fatalf("after the second dial connected: %+v", d)
- }
- }
- })
-}
-
-// A first dial that never reports holds nobody past holderConnectWait:
-// its waiters are refused, and a request after the gate's time dials again.
-func TestFirstDialWaitIsBounded(t *testing.T) {
- s := haHeldByB(t)
- clk := &fakeClock{t: time.Now()}
- s.a.holders.now = clk.now
- first := s.decide()
- start := time.Now()
- if d := s.decide(); !d.Refuse {
- t.Fatalf("a waiter on a dial that never reports: %+v, want a refusal", d)
+ s.a.holders.mu.Lock()
+ seq := s.a.holders.seq
+ s.a.holders.mu.Unlock()
+ for _, d := range ds {
+ s.note(d, edge.ForwardResult{Outcome: edge.ForwardUnreachable})
}
- if took := time.Since(start); took < holderConnectWait-100*time.Millisecond || took > holderConnectWait+time.Second {
- t.Fatalf("the waiter waited %v, want about %v", took, holderConnectWait)
+ s.a.holders.mu.Lock()
+ landed := s.a.holders.seq - seq
+ s.a.holders.mu.Unlock()
+ if landed != 1 || reads.Load() != 1 {
+ t.Fatalf("20 failures under one gen changed the entry %d times with %d reads, want 1 and 1", landed, reads.Load())
}
- clk.advance(holderConnectWait)
- if d := s.decide(); d.Ref != "b" || d.Gen == first.Gen {
- t.Fatalf("after the gate's time: %+v, want a new dial", d)
+ if d := s.decide(); !d.Refuse {
+ t.Fatalf("after the failures: %+v, want a refusal", d)
}
}
@@ -341,16 +256,70 @@ func TestSuspectRevalidationFailureRenewsTheWindow(t *testing.T) {
})
}
+// A forward that answers while a suspect's revalidation read runs is
+// newer news: the read's failure no longer renews the suspicion, and the
+// box that answered is the holder. It never recreates an entry that this
+// box taking the lease removed meanwhile.
+func TestSuccessDuringRevalidationWins(t *testing.T) {
+ holdRead := func(t *testing.T) (started func() bool, release func()) {
+ t.Helper()
+ gate := make(chan struct{})
+ var reads atomic.Int32
+ old := readHolderLock
+ readHolderLock = func(ctx context.Context, _, _, _ string) (hafresh.View, error) {
+ reads.Add(1)
+ <-gate
+ return hafresh.View{}, context.DeadlineExceeded
+ }
+ t.Cleanup(func() { readHolderLock = old })
+ return func() bool { return reads.Load() == 1 }, func() { close(gate) }
+ }
+ t.Run("success", func(t *testing.T) {
+ s, clk := suspectB(t)
+ clk.advance(holderSuspectTTL + time.Millisecond)
+ started, release := holdRead(t)
+ got := s.concurrently(1)
+ waitFor(t, "the revalidation read", started)
+ s.a.NoteForward(s.rt.Host, edge.ForwardResult{Outcome: edge.ForwardDone, Ref: "b", Status: http.StatusOK})
+ release()
+ if d := recv(t, got); d.Refuse || d.Ref != "b" {
+ t.Fatalf("the revalidating request after b answered and the read failed: %+v, want a forward to b", d)
+ }
+ if ref, positive, _ := s.a.holders.get(s.rt.Host); ref != "b" || !positive {
+ t.Fatalf("the entry is %q (positive %v), want b", ref, positive)
+ }
+ })
+ t.Run("lease acquisition first", func(t *testing.T) {
+ s := haService(t, "shop.example.com")
+ s.rt.HA = true
+ clk := &fakeClock{t: time.Now()}
+ s.a.holders.now = clk.now
+ s.a.holders.set(s.rt.Host, "b")
+ s.note(s.decide(), edge.ForwardResult{Outcome: edge.ForwardUnreachable})
+ clk.advance(holderSuspectTTL + time.Millisecond)
+ started, release := holdRead(t)
+ got := s.concurrently(1)
+ waitFor(t, "the revalidation read", started)
+ if _, err := s.wakeForTest(context.Background()); err != nil {
+ t.Fatalf("wake: %v", err)
+ }
+ s.a.NoteForward(s.rt.Host, edge.ForwardResult{Outcome: edge.ForwardDone, Ref: "b", Status: http.StatusOK})
+ release()
+ recv(t, got)
+ if _, _, found := s.a.holders.get(s.rt.Host); found {
+ t.Fatal("an entry came back after this box took the lease")
+ }
+ })
+}
+
// An unreachable outcome older than the cache's news is ignored: it cannot
// make a holder suspect again after a success, a holder header, or this box
// taking the lease cleared it.
func TestStaleUnreachableIsIgnored(t *testing.T) {
- // three forwards to b outstanding on one confirmed connection.
+ // three forwards to b outstanding under one generation.
outstanding := func(t *testing.T, s *haSvc) (d1, d2, d3 edge.ForwardDecision) {
t.Helper()
- d1 = s.decide()
- s.a.NoteConnected(s.rt.Host, d1.Gen)
- d2, d3 = s.decide(), s.decide()
+ d1, d2, d3 = s.decide(), s.decide(), s.decide()
if d1.Ref != "b" || d2 != d1 || d3 != d1 {
t.Fatalf("decisions %+v %+v %+v, want three to b on one gen", d1, d2, d3)
}
diff --git a/internal/edge/backhaul_e2e_test.go b/internal/edge/backhaul_e2e_test.go
index 909491b1e..b91bf2625 100644
--- a/internal/edge/backhaul_e2e_test.go
+++ b/internal/edge/backhaul_e2e_test.go
@@ -243,6 +243,8 @@ type backhaulEdge struct {
local autocert.Cache
tlsAddr, plainAddr string
+ // door is the 443 server at tlsAddr.
+ door *httptest.Server
// calls counts requests that reached this box's 443 door, refusals
// included: "exactly one dial" and "never dialled at all" are both this
// number moving, or not, on the OTHER box.
@@ -385,6 +387,7 @@ func newBackhaulEdgeWith(t *testing.T, bucketDir, box string, ca *e2eCA, from *n
https.StartTLS()
t.Cleanup(https.Close)
be.tlsAddr = https.Listener.Addr().String()
+ be.door = https
// :80, the live boot's composed chain (boot).
plain := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
diff --git a/internal/edge/forwardha.go b/internal/edge/forwardha.go
index fa7e0e8b2..d6395046c 100644
--- a/internal/edge/forwardha.go
+++ b/internal/edge/forwardha.go
@@ -22,7 +22,6 @@ import (
"fmt"
"net"
"net/http"
- "net/http/httptrace"
"sync"
"time"
@@ -34,15 +33,12 @@ import (
// activator, forwards nothing.
//
// ForwardTarget says what to do with a request for rt: forward it to a box,
-// refuse it at the front door, or serve it here. NoteConnected reports that a
-// forward's connection to the box (TCP and TLS) was made, before any answer;
-// NoteForward reports how the forward ended. Both carry the decision's Gen,
-// so the activator's holder cache can follow them and ignore an outcome older
-// than what it has learned since. host is rt.Host, the route's own host,
-// never an alias the request named.
+// refuse it at the front door, or serve it here. NoteForward reports how a
+// forward went, with the decision's Gen, so the activator's holder cache can
+// follow it and ignore an outcome older than what it has learned since. host
+// is rt.Host, the route's own host, never an alias the request named.
type HAForwarder interface {
ForwardTarget(ctx context.Context, rt registry.Route) ForwardDecision
- NoteConnected(host string, gen uint64)
NoteForward(host string, res ForwardResult)
}
@@ -55,8 +51,8 @@ type ForwardDecision struct {
// is answered (503, Retry-After: 10), without forwarding it or running
// anything else: the host's holder did not answer a forward moments ago.
Refuse bool
- // Gen is the activator's token for this forward, handed back on
- // NoteConnected and in ForwardResult.
+ // Gen is the activator's token for this forward, handed back in
+ // ForwardResult.
Gen uint64
}
@@ -116,10 +112,6 @@ func stripAppHolder(resp *http.Response) {
// the visitor to come back once the activator has looked again).
const forwardDialTimeout = 2 * time.Second
-// ForwardDialTimeout is forwardDialTimeout, for the activator: how long a
-// forward's first connection to a holder can take.
-const ForwardDialTimeout = forwardDialTimeout
-
// forwardDial makes the TCP connection to a holder at addr. A var only so a
// test can point it at another listener or make it stall; the deadline is on
// ctx.
@@ -142,8 +134,7 @@ func (e *forwardConnectError) Unwrap() error { return e.err }
// reached through a regional name, and the activator names a box or refuses.
// A refusal is answered here as an unreachable forward is, and nothing is
// dialled or noted. Otherwise the request is forwarded, the activator is told
-// when its connection is made and how it went, and it is answered unless the
-// box was not in view.
+// how it went, and it is answered unless the box was not in view.
func (e *Edge) frontForwardHA(w http.ResponseWriter, r *http.Request, host string, up upstream, hopped, isDoor bool) bool {
if hopped || isDoor || hopVerified(r.Context()) || fromTunnel(r.Context()) {
return false
@@ -163,24 +154,21 @@ func (e *Edge) frontForwardHA(w http.ResponseWriter, r *http.Request, host strin
if d.Ref == "" {
return false
}
- routeHost := up.route.Host
- res := e.forwardHA(w, r, host, d, func() { fw.NoteConnected(routeHost, d.Gen) })
- fw.NoteForward(routeHost, res)
+ res := e.forwardHA(w, r, host, d)
+ fw.NoteForward(up.route.Host, res)
return res.Outcome != ForwardNotInView
}
// forwardHA sends r to the box labelled d.Ref over a signed hop for host. A
// box out of view, or no mesh key, writes nothing and answers
// ForwardNotInView. Otherwise the hop is admitted and signed as backhaulTo's
-// is, over this edge's forward transport to the box. connected, when not nil,
-// is called once when the transport has the connection (GotConn: dialled, TCP
-// and TLS, or reused), before the request is written, so a slow answer never
-// delays it. A failure to connect is answered 503, Retry-After: 10; every
-// other answer is the holder's, relayed as is.
+// is, over this edge's forward transport to the box. A failure to connect is
+// answered 503, Retry-After: 10; every other answer is the holder's, relayed
+// as is.
//
// It repeats the arrived-hop guard: a verified hop is never forwarded, so a
// forwarding loop needs this line and frontForwardHA's to be wrong at once.
-func (e *Edge) forwardHA(w http.ResponseWriter, r *http.Request, host string, d ForwardDecision, connected func()) ForwardResult {
+func (e *Edge) forwardHA(w http.ResponseWriter, r *http.Request, host string, d ForwardDecision) ForwardResult {
ref := d.Ref
res := ForwardResult{Outcome: ForwardNotInView, Ref: ref, Gen: d.Gen}
m := e.homes.Load()
@@ -197,12 +185,6 @@ func (e *Edge) forwardHA(w http.ResponseWriter, r *http.Request, host string, d
return res
}
res.Outcome = ForwardDone
- if connected != nil {
- var once sync.Once
- r = r.WithContext(httptrace.WithClientTrace(r.Context(), &httptrace.ClientTrace{
- GotConn: func(httptrace.GotConnInfo) { once.Do(connected) },
- }))
- }
onError := func(w http.ResponseWriter, r *http.Request, err error) {
var connect *forwardConnectError
if errors.As(err, &connect) && r.Context().Err() == nil {
@@ -237,6 +219,10 @@ func answerHolderUnreachable(w http.ResponseWriter, r *http.Request) {
// is a forwardConnectError. A separate cache, so backhaulTo's 5 s transports
// to the same address are never this one.
//
+// Its TCP dials go through one forwardDialGate, the transport being one per
+// holder address: at most one dial to a holder is in flight, however many
+// requests need a connection and whatever the holder cache believes.
+//
// It does the TLS itself (DialTLSContext) so that the deadline and the error
// mark cover the handshake too. Verification is backhaulTransport's: the
// system roots (backhaulRootCAs) and the host from the outbound URL's
@@ -246,6 +232,7 @@ func (e *Edge) forwardTransport(dial string) *http.Transport {
if tr, ok := e.forwardTransports.Load(dial); ok {
return tr.(*http.Transport)
}
+ gate := &forwardDialGate{}
tr := &http.Transport{
DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
name, _, err := net.SplitHostPort(addr)
@@ -254,7 +241,9 @@ func (e *Edge) forwardTransport(dial string) *http.Transport {
}
ctx, cancel := context.WithTimeout(ctx, forwardDialTimeout)
defer cancel()
- raw, err := forwardDial(ctx, network, net.JoinHostPort(dial, backhaulPort))
+ raw, err := gate.dial(ctx, func(ctx context.Context) (net.Conn, error) {
+ return forwardDial(ctx, network, net.JoinHostPort(dial, backhaulPort))
+ })
if err != nil {
return nil, &forwardConnectError{err}
}
@@ -280,3 +269,59 @@ func (e *Edge) forwardTransport(dial string) *http.Transport {
}
return tr
}
+
+// forwardDialGate coalesces one holder address's TCP dials: at most one is
+// in flight. A dial that arrives while one is in flight waits for its
+// outcome, within its own deadline. When that dial fails, every waiter fails
+// with its error at once, and so does every dial that arrives until the
+// failed one's forwardDialTimeout has run out: a box that refuses at once
+// costs no more dials than one that does not answer. When it connects,
+// each waiter dials its own connection. The dial in flight runs detached
+// from its own caller's cancellation, so a visitor hanging up does not fail
+// the others; forwardDialTimeout bounds it.
+type forwardDialGate struct {
+ mu sync.Mutex
+ last *forwardDialCall
+}
+
+type forwardDialCall struct {
+ done chan struct{}
+ err error
+ until time.Time // a failure answers later dials until then
+}
+
+func (g *forwardDialGate) dial(ctx context.Context, connect func(context.Context) (net.Conn, error)) (net.Conn, error) {
+ g.mu.Lock()
+ if c := g.last; c != nil {
+ select {
+ case <-c.done:
+ if c.err != nil && time.Now().Before(c.until) {
+ g.mu.Unlock()
+ return nil, c.err
+ }
+ default:
+ g.mu.Unlock()
+ select {
+ case <-c.done:
+ case <-ctx.Done():
+ return nil, ctx.Err()
+ }
+ if c.err != nil {
+ return nil, c.err
+ }
+ return connect(ctx)
+ }
+ }
+ c := &forwardDialCall{done: make(chan struct{})}
+ g.last = c
+ g.mu.Unlock()
+ start := time.Now()
+ dctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), forwardDialTimeout)
+ defer cancel()
+ conn, err := connect(dctx)
+ g.mu.Lock()
+ c.err, c.until = err, start.Add(forwardDialTimeout)
+ close(c.done)
+ g.mu.Unlock()
+ return conn, err
+}
diff --git a/internal/edge/forwardha_export_test.go b/internal/edge/forwardha_export_test.go
new file mode 100644
index 000000000..0b54ad493
--- /dev/null
+++ b/internal/edge/forwardha_export_test.go
@@ -0,0 +1,76 @@
+package edge
+
+import (
+ "context"
+ "io"
+ "net"
+ "net/http"
+ "sync/atomic"
+ "testing"
+)
+
+// The forward scene (forwardha_test.go) for forwardha_wiring_test.go, the
+// guard test that drives the real activator through the real edge. It must
+// be package edge_test, because the activator imports this package; these
+// names exist only in this package's test build.
+
+// HAForwardHost is the born-HA host both boxes of the scene serve.
+const HAForwardHost = fwHost
+
+// HAForwardHolder is the holder box's ref in the scene.
+const HAForwardHolder = "betty"
+
+// HAForwardScene is a forward scene whose forwarding box (annie) runs act,
+// with every forward dial counted at the dial seam.
+type HAForwardScene struct {
+ x *fwScene
+ dials atomic.Int64
+ stall atomic.Bool
+}
+
+// NewHAForwardScene is newFwScene with act as annie's activator.
+func NewHAForwardScene(t *testing.T, act Activator) *HAForwardScene {
+ t.Helper()
+ s := &HAForwardScene{x: newFwScene(t, fwOpts{aAct: act})}
+ addr := s.x.b.tlsAddr
+ old := forwardDial
+ forwardDial = func(ctx context.Context, network, _ string) (net.Conn, error) {
+ s.dials.Add(1)
+ if s.stall.Load() {
+ <-ctx.Done()
+ return nil, ctx.Err()
+ }
+ var d net.Dialer
+ return d.DialContext(ctx, network, addr)
+ }
+ t.Cleanup(func() { forwardDial = old })
+ return s
+}
+
+// Dials is the number of forward dials to the holder so far.
+func (s *HAForwardScene) Dials() int64 { return s.dials.Load() }
+
+// Get is one visitor GET of path on HAForwardHost through annie.
+func (s *HAForwardScene) Get(path string) (status int, retryAfter, body string, err error) {
+ resp, err := s.x.a.client.Get("https://" + fwHost + path)
+ if err != nil {
+ return 0, "", "", err
+ }
+ defer resp.Body.Close()
+ b, err := io.ReadAll(resp.Body)
+ return resp.StatusCode, resp.Header.Get("Retry-After"), string(b), err
+}
+
+// HolderDown is the holder box gone: its door's listener closed and its
+// connections cut, and annie's idle forward connections dropped. With
+// blackholed, a dial to it also stalls until its deadline, as a dial to a
+// terminated box's address does, rather than being refused at once.
+func (s *HAForwardScene) HolderDown(blackholed bool) {
+ s.stall.Store(blackholed)
+ s.x.b.door.Listener.Close()
+ s.x.b.door.CloseClientConnections()
+ s.x.a.edge.forwardTransports.Range(func(_, v any) bool {
+ v.(*http.Transport).CloseIdleConnections()
+ return true
+ })
+}
diff --git a/internal/edge/forwardha_test.go b/internal/edge/forwardha_test.go
index b9315ad79..5190ef645 100644
--- a/internal/edge/forwardha_test.go
+++ b/internal/edge/forwardha_test.go
@@ -16,6 +16,7 @@ import (
"bufio"
"context"
"crypto/tls"
+ "errors"
"fmt"
"io"
"net"
@@ -62,18 +63,12 @@ var fwHosts = []string{fwHost, fwGatedHost, fwAssetHost, fwRateHost, fwLegacyHos
// answers) and, as an HAForwarder, names target (or refuses, when refuse is
// set) and keeps every note.
type fwAct struct {
- target string
- refuse bool
- gen uint64
- asked atomic.Int64
- mu sync.Mutex
- notes []fwNote
- connects []fwConnect
-}
-
-type fwConnect struct {
- host string
- gen uint64
+ target string
+ refuse bool
+ gen uint64
+ asked atomic.Int64
+ mu sync.Mutex
+ notes []fwNote
}
type fwNote struct {
@@ -100,17 +95,7 @@ func (a *fwAct) ForwardTarget(_ context.Context, _ registry.Route) ForwardDecisi
a.asked.Add(1)
return ForwardDecision{Ref: a.target, Refuse: a.refuse, Gen: a.gen}
}
-func (a *fwAct) NoteConnected(host string, gen uint64) {
- a.mu.Lock()
- defer a.mu.Unlock()
- a.connects = append(a.connects, fwConnect{host, gen})
-}
-func (a *fwAct) connected() []fwConnect {
- a.mu.Lock()
- defer a.mu.Unlock()
- return append([]fwConnect(nil), a.connects...)
-}
func (a *fwAct) NoteForward(host string, res ForwardResult) {
a.mu.Lock()
defer a.mu.Unlock()
@@ -672,8 +657,8 @@ func TestFrontForwardSuspectRefusalRunsNoLocalStep(t *testing.T) {
if n := x.b.calls.Load() - calls; n != 0 {
t.Fatalf("betty saw %d requests, want none", n)
}
- if notes, c := x.aAct.noted(), x.aAct.connected(); len(notes) != 0 || len(c) != 0 {
- t.Fatalf("notes = %+v, connections %+v, want none: nothing was forwarded", notes, c)
+ if notes := x.aAct.noted(); len(notes) != 0 {
+ t.Fatalf("notes = %+v, want none: nothing was forwarded", notes)
}
if got := x.aAct.asked.Load(); got != int64(len(cases)) {
t.Fatalf("annie asked its activator %d times, want %d", got, len(cases))
@@ -686,36 +671,137 @@ func TestFrontForwardSuspectRefusalRunsNoLocalStep(t *testing.T) {
}
}
-// The activator hears of a forward's connection when the transport has it,
-// before the holder answers, so a slow app never holds the activator's
-// connection gate; both notes carry the decision's Gen.
-func TestForwardHAConnectedBeforeTheAnswer(t *testing.T) {
+// The decision's Gen comes back in the forward's note.
+func TestForwardHANoteCarriesTheGen(t *testing.T) {
x := newFwScene(t, fwOpts{})
x.aAct.gen = 7
- lead := x.fetchAsync(fwAssetHost, "/assets/held.js")
- e2eStarted(t, x.bApp.started, lead) // betty's app holds the answer
- c, notes := x.aAct.connected(), x.aAct.noted()
- x.bApp.release() // before any failure, so the scene can close
- if len(c) != 1 || c[0] != (fwConnect{fwAssetHost, 7}) {
- t.Fatalf("connections noted while the holder's app held the answer: %+v, want one for gen 7", c)
- }
- if len(notes) != 0 {
- t.Fatalf("the forward ended before its answer: %+v", notes)
- }
- if r := e2eAwait(t, lead); r.resp.StatusCode != http.StatusOK || r.body != fwAssetBody {
- t.Fatalf("GET = %d %q", r.resp.StatusCode, r.body)
- }
- x.wantNote(t, fwNote{fwAssetHost, ForwardResult{Outcome: ForwardDone, Ref: "betty", Gen: 7, Status: http.StatusOK}})
- if c := x.aAct.connected(); len(c) != 1 {
- t.Fatalf("connections %+v, want the one", c)
- }
- // A reused connection is a connection too.
if resp, _ := x.fetch(t, fwHost, "/"); resp.StatusCode != http.StatusOK {
- t.Fatalf("second GET = %d", resp.StatusCode)
- }
- if c := x.aAct.connected(); len(c) != 2 || c[1] != (fwConnect{fwHost, 7}) {
- t.Fatalf("connections %+v, want a second for %s", c, fwHost)
+ t.Fatalf("GET = %d", resp.StatusCode)
}
+ x.wantNote(t, fwNote{fwHost, ForwardResult{Outcome: ForwardDone, Ref: "betty", Gen: 7, Status: http.StatusOK}})
+}
+
+// The forward transport's dial gate: one dial in flight per holder address.
+// Dials that arrive meanwhile wait for it; a failure answers them, and every
+// dial until its forwardDialTimeout runs out, with no dial of their own; a
+// success lets each dial its own.
+func TestForwardDialGate(t *testing.T) {
+ ctx := context.Background()
+ t.Run("a failure answers its waiters and what follows", func(t *testing.T) {
+ g := &forwardDialGate{}
+ var dials atomic.Int64
+ release := make(chan struct{})
+ refused := errors.New("connection refused")
+ connect := func(context.Context) (net.Conn, error) {
+ if dials.Add(1) == 1 {
+ <-release
+ }
+ return nil, refused
+ }
+ errs := make(chan error, 20)
+ for range 20 {
+ go func() { _, err := g.dial(ctx, connect); errs <- err }()
+ }
+ laWaitFor(t, "the first dial", func() bool { return dials.Load() == 1 })
+ time.Sleep(50 * time.Millisecond)
+ if n := dials.Load(); n != 1 {
+ t.Fatalf("%d dials in flight, want 1", n)
+ }
+ close(release)
+ for range 20 {
+ if err := <-errs; !errors.Is(err, refused) {
+ t.Fatalf("a waiter got %v, want the dial's error", err)
+ }
+ }
+ if _, err := g.dial(ctx, connect); !errors.Is(err, refused) || dials.Load() != 1 {
+ t.Fatalf("a dial right after the failure: %v with %d dials, want the failure and 1", err, dials.Load())
+ }
+ g.mu.Lock()
+ g.last.until = time.Now() // the failure's time is up
+ g.mu.Unlock()
+ g.dial(ctx, connect)
+ if n := dials.Load(); n != 2 {
+ t.Fatalf("after the failure's time: %d dials, want 2", n)
+ }
+ })
+ t.Run("a success lets each waiter dial", func(t *testing.T) {
+ g := &forwardDialGate{}
+ var dials, inFlight, most atomic.Int64
+ release := make(chan struct{})
+ connect := func(context.Context) (net.Conn, error) {
+ n := inFlight.Add(1)
+ defer inFlight.Add(-1)
+ for m := most.Load(); n > m && !most.CompareAndSwap(m, n); m = most.Load() {
+ }
+ if dials.Add(1) == 1 {
+ <-release
+ }
+ a, b := net.Pipe()
+ b.Close()
+ return a, nil
+ }
+ errs := make(chan error, 5)
+ for range 5 {
+ go func() {
+ conn, err := g.dial(ctx, connect)
+ if conn != nil {
+ conn.Close()
+ }
+ errs <- err
+ }()
+ }
+ laWaitFor(t, "the first dial", func() bool { return dials.Load() == 1 })
+ time.Sleep(50 * time.Millisecond)
+ if most.Load() != 1 {
+ t.Fatalf("%d dials in flight before the first connected, want 1", most.Load())
+ }
+ close(release)
+ for range 5 {
+ if err := <-errs; err != nil {
+ t.Fatalf("a dial after a success: %v", err)
+ }
+ }
+ if n := dials.Load(); n != 5 {
+ t.Fatalf("%d dials, want one each", n)
+ }
+ })
+ t.Run("a waiter's own deadline", func(t *testing.T) {
+ g := &forwardDialGate{}
+ release := make(chan struct{})
+ defer close(release)
+ go g.dial(ctx, func(context.Context) (net.Conn, error) { <-release; return nil, errors.New("late") })
+ laWaitFor(t, "the first dial", func() bool { g.mu.Lock(); defer g.mu.Unlock(); return g.last != nil })
+ wctx, cancel := context.WithTimeout(ctx, 50*time.Millisecond)
+ defer cancel()
+ if _, err := g.dial(wctx, func(context.Context) (net.Conn, error) { t.Error("the waiter dialled"); return nil, nil }); !errors.Is(err, context.DeadlineExceeded) {
+ t.Fatalf("a waiter past its deadline: %v", err)
+ }
+ })
+ t.Run("the dial outlives its caller's hang-up", func(t *testing.T) {
+ g := &forwardDialGate{}
+ cctx, cancel := context.WithCancel(ctx)
+ started := make(chan struct{})
+ var sawCancel atomic.Bool
+ done := make(chan struct{})
+ go func() {
+ defer close(done)
+ g.dial(cctx, func(dctx context.Context) (net.Conn, error) {
+ close(started)
+ select {
+ case <-dctx.Done():
+ sawCancel.Store(true)
+ case <-time.After(100 * time.Millisecond):
+ }
+ return nil, errors.New("refused")
+ })
+ }()
+ <-started
+ cancel()
+ <-done
+ if sawCancel.Load() {
+ t.Fatal("the caller hanging up cancelled the dial its waiters share")
+ }
+ })
}
func TestForwardHAHolderLostHost(t *testing.T) {
@@ -900,9 +986,6 @@ func TestForwardHADialFailureIs503RetryTen(t *testing.T) {
if len(notes) == 0 || notes[len(notes)-1] != (fwNote{fwHost, ForwardResult{Outcome: ForwardUnreachable, Ref: "betty"}}) {
t.Fatalf("notes = %+v, want ForwardUnreachable last", notes)
}
- if c := x.aAct.connected(); len(c) != 0 {
- t.Fatalf("an unreachable forward noted a connection: %+v", c)
- }
if n := x.bApp.n.Load(); n != 0 {
t.Fatalf("betty's app saw %d requests", n)
}
diff --git a/internal/edge/forwardha_wiring_test.go b/internal/edge/forwardha_wiring_test.go
new file mode 100644
index 000000000..dd059620a
--- /dev/null
+++ b/internal/edge/forwardha_wiring_test.go
@@ -0,0 +1,106 @@
+// The dead-holder guard test (region HA P1b-2 follow-up): the real
+// activator, through the real edge, against a holder that served and then
+// went away while its lease and this box's cache entry stay live. It is
+// package edge_test because the activator imports internal/edge; the scene
+// comes from forwardha_export_test.go.
+package edge_test
+
+import (
+ "encoding/json"
+ "sync"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/activator"
+ "github.com/carlosframework/platform/internal/edge"
+ "github.com/carlosframework/platform/internal/hafresh"
+ "github.com/carlosframework/platform/internal/lease/locktest"
+)
+
+const unreachableBody = "instance is waking elsewhere; retry shortly\n"
+
+func TestDeadHolderGuardRealWiring(t *testing.T) {
+ for _, c := range []struct {
+ name string
+ blackholed bool
+ }{{"refused", false}, {"blackholed", true}} {
+ t.Run(c.name, func(t *testing.T) { deadHolderGuard(t, c.blackholed) })
+ }
+}
+
+func deadHolderGuard(t *testing.T, blackholed bool) {
+ fx := locktest.NewLockFixture(t)
+ prefix := activator.HibernatePrefix("", edge.HAForwardHost)
+ lockGets := func() int {
+ n := 0
+ for _, r := range fx.Requests() {
+ if r == "GET "+prefix+"/lock.json" {
+ n++
+ }
+ }
+ return n
+ }
+ body, err := json.Marshal(hafresh.Lock{Generation: 9, ExpiresAt: time.Now().Add(10 * time.Minute).UTC(),
+ Owner: "box/v1;ref=" + edge.HAForwardHolder + ";iid=i-b;pid=7;ha=1"})
+ if err != nil {
+ t.Fatal(err)
+ }
+ fx.PutLock(prefix, body)
+ cfg := activator.Config{Bucket: fx.Bucket, Idle: time.Hour,
+ Self: func() hafresh.Self { return hafresh.Self{Ref: "annie", IID: "i-a"} }}
+ svc := activator.New(cfg, &activator.ExecBackend{Cfg: cfg}, nil)
+ x := edge.NewHAForwardScene(t, svc)
+
+ // The holder serves one forward.
+ if status, _, got, err := x.Get("/"); err != nil || status != 200 || got != "betty|"+edge.HAForwardHost+"|/" {
+ t.Fatalf("the first forward: %d %q %v, want betty's 200", status, got, err)
+ }
+ if x.Dials() != 1 || lockGets() != 1 {
+ t.Fatalf("the first forward: %d dials and %d lock reads, want 1 and 1", x.Dials(), lockGets())
+ }
+
+ // The holder goes away; its lease and the cache entry stay live.
+ x.HolderDown(blackholed)
+ dials, reads := x.Dials(), lockGets()
+ var wg sync.WaitGroup
+ type answer struct {
+ status int
+ retry, body string
+ err error
+ }
+ answers := make([]answer, 20)
+ for i := range answers {
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+ var a answer
+ a.status, a.retry, a.body, a.err = x.Get("/")
+ answers[i] = a
+ }()
+ }
+ wg.Wait()
+ for i, a := range answers {
+ if a.err != nil || a.status != 503 || a.retry != "10" || a.body != unreachableBody {
+ t.Fatalf("request %d: %d Retry-After %q %q %v, want 503, 10", i, a.status, a.retry, a.body, a.err)
+ }
+ }
+ if n, m := x.Dials()-dials, lockGets()-reads; n != 1 || m != 0 {
+ t.Fatalf("20 concurrent requests for a gone holder: %d dials and %d lock reads, want 1 and 0", n, m)
+ }
+
+ // Within the window: refused at the front door, nothing dialled or read.
+ dials, reads = x.Dials(), lockGets()
+ start := time.Now()
+ for i := range 10 {
+ status, retry, got, err := x.Get("/")
+ if err != nil || status != 503 || retry != "10" || got != unreachableBody {
+ t.Fatalf("sequential request %d: %d Retry-After %q %q %v", i, status, retry, got, err)
+ }
+ }
+ if took := time.Since(start); took >= 10*time.Second {
+ t.Fatalf("the sequential requests took %v, past the window", took)
+ }
+ if n, m := x.Dials()-dials, lockGets()-reads; n != 0 || m != 0 {
+ t.Fatalf("sequential requests within the window: %d dials and %d lock reads, want 0 and 0", n, m)
+ }
+}
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index f177e774d..8822f252f 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -38,4 +38,4 @@ plan14-root-reads-rootfs-check-volumes.tsv 042684bf5af6f61ce8b87f10b68a42b08d131
plan14-root-reads-rootfs-fleet-followups.tsv 78b7e7e30ad3ada44388a4ee16f3950ef888ae03e552477dcbfbb07c51ffb83e
plan14-root-reads-rootfs-worker-exit.tsv 7ebc3871ee3c93ff168bfa62d23d6be5a970786c67a9b8aa813e8cc4e39b3d74
plan14-root-reads-region-ha-p1b2.tsv 5b559ba7a42084908cb0fec08083bb2b9b3c9d960036fd10418f81e56304bb64
-plan14-root-reads-region-ha-dead-holder-backoff.tsv 61dc010abf76d6f3a17f9b376935d8c440f53a32ca866923c55a6069ca1dc343
+plan14-root-reads-region-ha-dead-holder-backoff.tsv 8f6a1865b0abcea9d4fb68232cc2a25263a106ec87f73bd4b3f2fb388971ebe5
diff --git a/internal/provision/testdata/plan14-root-reads-region-ha-dead-holder-backoff.tsv b/internal/provision/testdata/plan14-root-reads-region-ha-dead-holder-backoff.tsv
index 7dad283bb..818a16697 100644
--- a/internal/provision/testdata/plan14-root-reads-region-ha-dead-holder-backoff.tsv
+++ b/internal/provision/testdata/plan14-root-reads-region-ha-dead-holder-backoff.tsv
@@ -1,8 +1,8 @@
# Census overlay region-ha-dead-holder-backoff, written by census-propose (#369). census-ruling-region-ha-dead-holder-backoff, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-region-ha-dead-holder-backoff.md.
# 1 body, 1 sites, 2 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
-@legacy 0894a9cd7b848374744a74d20b4d22146a1faa68c81837b9736b00b9668c28c9 internal/edge/forwardha.go Edge.frontForwardHA legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p1b2;basis=new (region HA P1b-2): the agent's edge decides at the front door whether to forward a visitor request: reads the route's HA flag and host from the box's own registry row and asks the activator; forwards only to a box in view over the existing signed hop; root never calls it;rev3=census-ruling-region-ha-dead-holder-backoff;basis=ForwardTarget returns a ForwardDecision (Ref, Refuse, Gen); a Refuse is answered at the front door with the existing unreachable answer (503, Retry-After: 10, same body, via answerHolderUnreachable), with no forward, dial, note or per-request step. A forward now passes the decision to forwardHA with a callback that calls the activator's NoteConnected(route host, Gen) once when the transport has the connection (httptrace GotConn), and NoteForward carries Ref and Gen back. The route host is read once into a local; the same 5 read sites; no new read; root never calls it. registry:HA@225,registry:Host@526,whole:Route@228,whole:Route@405,whole:Route@529 b59a0937fffae087d6110f186b6386bd9bf1e3856b2724d5801ea22d7a24972f
-@legacy 4c7837d8c69d43b7c8c23da4a866768482974b4f7a66e292e7ad55b0232e6873 internal/activator/haforward.go Service.ForwardTarget legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p1b2;basis=new (region HA P1b-2): the agent's activator answers the edge with a holder box ref for an HA route not awake here, from its in-memory holder cache or one bounded (2 s) lock.json read through readHolderView; reads the route's HA flag and host from its own registry row; root never calls it;rev3=census-ruling-region-ha-dead-holder-backoff;basis=Returns edge.ForwardDecision (Ref, Refuse, Gen) from holderCache.resolve, which is in memory only: a suspect holder refuses; a positive entry with no confirmed connection lets one request dial and the rest wait (bounded) on its connection; a failed read that revalidates an expired suspect keeps it suspect and refuses. The same single bounded (2 s) lock.json read through readHolderView on a miss; no new read and no new S3 request; root never calls it. registry:HA@100,registry:Host@1000,registry:Host@262,registry:Host@383,whole:Route@176,whole:Route@741 da8dcb16995990c9fb3c7107cd0d1ef8d5424bddea08a70ad8133801b186cc53
-internal/edge/forwardha.go Edge.frontForwardHA legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p1b2;basis=new (region HA P1b-2): the agent's edge decides at the front door whether to forward a visitor request: reads the route's HA flag and host from the box's own registry row and asks the activator; forwards only to a box in view over the existing signed hop; root never calls it;rev3=census-ruling-region-ha-dead-holder-backoff;basis=ForwardTarget returns a ForwardDecision (Ref, Refuse, Gen); a Refuse is answered at the front door with the existing unreachable answer (503, Retry-After: 10, same body, via answerHolderUnreachable), with no forward, dial, note or per-request step. A forward now passes the decision to forwardHA with a callback that calls the activator's NoteConnected(route host, Gen) once when the transport has the connection (httptrace GotConn), and NoteForward carries Ref and Gen back. The route host is read once into a local; the same 5 read sites; no new read; root never calls it. registry:HA@225,registry:Host@526,whole:Route@228,whole:Route@405,whole:Route@529 b59a0937fffae087d6110f186b6386bd9bf1e3856b2724d5801ea22d7a24972f
-internal/activator/haforward.go Service.ForwardTarget legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p1b2;basis=new (region HA P1b-2): the agent's activator answers the edge with a holder box ref for an HA route not awake here, from its in-memory holder cache or one bounded (2 s) lock.json read through readHolderView; reads the route's HA flag and host from its own registry row; root never calls it;rev3=census-ruling-region-ha-dead-holder-backoff;basis=Returns edge.ForwardDecision (Ref, Refuse, Gen) from holderCache.resolve, which is in memory only: a suspect holder refuses; a positive entry with no confirmed connection lets one request dial and the rest wait (bounded) on its connection; a failed read that revalidates an expired suspect keeps it suspect and refuses. The same single bounded (2 s) lock.json read through readHolderView on a miss; no new read and no new S3 request; root never calls it. registry:HA@100,registry:Host@1000,registry:Host@262,registry:Host@383,whole:Route@176,whole:Route@741 da8dcb16995990c9fb3c7107cd0d1ef8d5424bddea08a70ad8133801b186cc53
-@coverage internal/activator 1906e2441d0c70113216a152742cd7cf7b0d808ab9b13a4bee6f3201d885c698
-@coverage internal/edge 6f55508cbaea459f5bce73565981c4992893765e00dff1f1fa2a9e411a4b010d
+@legacy b286076f631f312f8205e0fb21e469fc58c59f1e910fb7e2becb0ffabc36d0f1 internal/edge/forwardha.go Edge.frontForwardHA legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p1b2;basis=new (region HA P1b-2): the agent's edge decides at the front door whether to forward a visitor request: reads the route's HA flag and host from the box's own registry row and asks the activator; forwards only to a box in view over the existing signed hop; root never calls it;rev3=census-ruling-region-ha-dead-holder-backoff;basis=ForwardTarget returns a ForwardDecision (Ref, Refuse, Gen); a Refuse is answered at the front door with the existing unreachable answer (503, Retry-After: 10, same body, via answerHolderUnreachable), with no forward, dial, note or per-request step. A forward passes the decision to forwardHA and NoteForward carries Ref and Gen back. The round-1 connection callback (NoteConnected) is gone: the dial bound now lives in forwardTransport's forwardDialGate, which coalesces TCP dials per holder address in memory. The same 5 read sites; no new read; root never calls it. registry:HA@225,registry:Host@563,whole:Route@228,whole:Route@405,whole:Route@566 c5b342e1a71cff53bdc6666821708f962c5b2fc73bd6cba2e983cff54c839626
+@legacy 98d129b191b29a10c516103399d33c1d72d5f2d992ed37211345da06bebcbb85 internal/activator/haforward.go Service.ForwardTarget legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p1b2;basis=new (region HA P1b-2): the agent's activator answers the edge with a holder box ref for an HA route not awake here, from its in-memory holder cache or one bounded (2 s) lock.json read through readHolderView; reads the route's HA flag and host from its own registry row; root never calls it;rev3=census-ruling-region-ha-dead-holder-backoff;basis=Returns edge.ForwardDecision (Ref, Refuse, Gen) from holderCache.resolve, in memory only: a suspect holder refuses; a positive entry forwards under its generation; a failed read that revalidates an expired suspect keeps it suspect and refuses. The round-1 cache connection gate is removed. The same single bounded (2 s) lock.json read through readHolderView on a miss; no new read and no new S3 request; root never calls it. registry:HA@100,registry:Host@1000,registry:Host@262,registry:Host@383,whole:Route@176,whole:Route@741 da8dcb16995990c9fb3c7107cd0d1ef8d5424bddea08a70ad8133801b186cc53
+internal/edge/forwardha.go Edge.frontForwardHA legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p1b2;basis=new (region HA P1b-2): the agent's edge decides at the front door whether to forward a visitor request: reads the route's HA flag and host from the box's own registry row and asks the activator; forwards only to a box in view over the existing signed hop; root never calls it;rev3=census-ruling-region-ha-dead-holder-backoff;basis=ForwardTarget returns a ForwardDecision (Ref, Refuse, Gen); a Refuse is answered at the front door with the existing unreachable answer (503, Retry-After: 10, same body, via answerHolderUnreachable), with no forward, dial, note or per-request step. A forward passes the decision to forwardHA and NoteForward carries Ref and Gen back. The round-1 connection callback (NoteConnected) is gone: the dial bound now lives in forwardTransport's forwardDialGate, which coalesces TCP dials per holder address in memory. The same 5 read sites; no new read; root never calls it. registry:HA@225,registry:Host@563,whole:Route@228,whole:Route@405,whole:Route@566 c5b342e1a71cff53bdc6666821708f962c5b2fc73bd6cba2e983cff54c839626
+internal/activator/haforward.go Service.ForwardTarget legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p1b2;basis=new (region HA P1b-2): the agent's activator answers the edge with a holder box ref for an HA route not awake here, from its in-memory holder cache or one bounded (2 s) lock.json read through readHolderView; reads the route's HA flag and host from its own registry row; root never calls it;rev3=census-ruling-region-ha-dead-holder-backoff;basis=Returns edge.ForwardDecision (Ref, Refuse, Gen) from holderCache.resolve, in memory only: a suspect holder refuses; a positive entry forwards under its generation; a failed read that revalidates an expired suspect keeps it suspect and refuses. The round-1 cache connection gate is removed. The same single bounded (2 s) lock.json read through readHolderView on a miss; no new read and no new S3 request; root never calls it. registry:HA@100,registry:Host@1000,registry:Host@262,registry:Host@383,whole:Route@176,whole:Route@741 da8dcb16995990c9fb3c7107cd0d1ef8d5424bddea08a70ad8133801b186cc53
+@coverage internal/activator d57a02d4526ac697a1885db1ffd483e922cb5529a0e90ba4c5a325c0f684f1a7
+@coverage internal/edge 725524c26589b9b81aeede93e89e42f1c7002bd122d8e112405a06cf0baef1a7