carlos / platform Public

Region HA dead-holder backoff, round 1 fixes (Astra R1 READY AFTER FIXES, three P2s; census approved at 39f6687d, re-proposed here). P2-1: a per-host connection gate. A positive holder entry with no confirmed connection lets one request dial; concurrent requests wait on that first connection, bounded by holderConnectWait (edge.ForwardDialTimeout plus 500 ms for the hop's set-up); when it connects they forward, when it cannot they get the suspect refusal, and a gate that never reports is abandoned so the next request dials. The connection is signalled from the transport (httptrace GotConn, dialled or reused, TCP and TLS) through the new HAForwarder.NoteConnected, before any answer, so a slow app never holds the gate; a confirmed connection lifts the gate until the entry changes. P2-2: a read that revalidates an expired suspect and fails (error or timeout) renews the window for the same box and refuses its initiator and waiters, unless news arrived while it ran. P2-3: every entry carries a generation, handed out with each forward (ForwardDecision.Gen, ForwardResult.Gen, NoteConnected) and renewed by every put, every first-connection attempt and every answer from the named box; removal invalidates it. An unreachable, connected or unconnected outcome under an older generation is ignored, so a stale failure cannot undo a success, a holder header or this box taking the lease. A read overtaken by news no longer hands out its uncached answer; its callers look again. N-HA10 kept, 50,000 bound kept, no new copy, no new S3 request. Witnesses: TestFirstDialGatesConcurrentRequests (20 concurrent requests, first dial held open: exactly one dial; connects, unreachable, ended without connecting), TestFirstDialWaitIsBounded, TestSuspectWindowEndForwardsOnce (now waiting on the connection), TestSuspectRevalidationFailureRenewsTheWindow (error, timeout, newer news), TestStaleUnreachableIsIgnored (same-ref success, holder header, lease acquisition), TestForwardHAConnectedBeforeTheAnswer (edge: GotConn while the holder's app holds the answer, Gen round-trips, reused connections count). Census re-proposed under the same NAME: Edge.frontForwardHA and Service.ForwardTarget 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 28fc3b906a7e4f857347b57908b534c57f41c339 parent 39f6687
10 files changed, +675 −184
  • 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 +247 −88
  • internal/activator/haforward.go +16 −5
  • internal/activator/haforward_test.go +19 −18
  • internal/activator/hasuspect_test.go +274 −34
  • internal/edge/forwardha.go +45 −18
  • internal/edge/forwardha_test.go +61 −8
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −1
  • internal/provision/testdata/plan14-root-reads-region-ha-dead-holder-backoff.tsv +6 −6

Intent

Human

<task-notification> <task-id>bo1y5tvpg</task-id> <tool-use-id>toolu_016N8pShoMhSjtS5N9sSiVro</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/953e7524-2e06-4308-b9ce-fd1b38579971/tasks/bo1y5tvpg.output</output-file> <status>completed</status> <summary>Background command "Wait for the Astra review to finish" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>a2996f62a17f2d23c</task-id> <tool-use-id>toolu_01D9gzeUQDSTZvpLxDZNyy8U</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/953e7524-2e06-4308-b9ce-fd1b38579971/tasks/a2996f62a17f2d23c.output</output-file> <status>completed</status> <summary>Agent "Cut v0.31.1 and roll dev" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>v0.31.1 is released and rolled to dev only, and every dev check passed. Flagship was not touched. Dev is ready for the P1b-2 drill, and CONSOLE_HA_REGIONS is still unset. The full detail is in /home/paulca/.cache/release-v0.31.1/roll-log.md. **Cut** - **Tag:** v0.31.1 (tag object 0d558604) on main bfc668c8. I checked main was unmoved and nothing newer than v0.31.0 existed before tagging. - **Main CI at bfc668c8 failed.** The only failure was TestReleaseLeaseLossUnprovenLeavesTheHold (internal/activator), whose settle started 0.2 µs after its deadline. That is the known flake #460. I recorded the ruling: main's tree 8f6099f0 is identical to the merged branch tip 90d2c802, which landed through the merge gate. Every other shard passed. - **Release:** [https://github.com/carlosframework/releases/releases/tag/v0.31.1](https://github.com/carlosframework/releases/releases/tag/v0.31.1), Latest, 10 assets. The public download's signature verified and its checksums match. - **Homebrew tap:** PR #71 merged. - **apt:** v0.31.1-1 is live (latest.txt reads v0.31.1, and the served deb matches the signed one). - **Build:** linux-arm64 sha 7021a2f2; console dc849550 with the full commit stamped. **Dev roll and checks (all passed)** - **Boxes:** sophie (canary), then leo and dennis (stable), are all v0.31.1 current and running 7021a2f2. - One listeners line each; REFUSING, LEASE HELD and ERROR all 0; NRestarts 0. - host.env sha8 unchanged on all three (leo bee523d2), and CARLOS_POOLS unchanged. - I copied the v0.31.1 binary over bootstrap/carlos to clear the status warning. - **box-1:** updated itself to v0.31.1 by 10:56:42Z (read from system status only). - **Console:** now v0.31.1 (dc849550). The restart took about 1.56 s from stop to serving. All 13 drop-ins and box files on sophie have identical sha8, owner and mode before and after. No ha-regions drop-in. - **#434 probe:** 1180 requests, none failed. Requests during the restart were held for at most 1.46 s, and there were no proxy errors. - **Standard checks:** x-carlos-version is v0.31.1, the billing webhook returns 400, and hosts-used is unchanged (36 recorded, floor v0.29.0). wakecheck woke on sophie (0.65 s) and claimtrial on leo (0.54 s). instances list and analytics work. - **Static site without `_headers`:** favicon.svg still has `no-cache`, the same Etag and X-Carlos-Version. The trailing-slash 301/200 is unchanged. - **Static site with `_headers`:** the throwaway app relcheck-headers works. `/assets/a.css` carries both headers, on its 304 too, and `/` keeps `no-cache`. `carlos ship` refused the `X-Frame-Options` file and named line 2. The app is deleted. - **Forwarding dormant:** 0 holder/forward lines in the sophie, leo and dennis edge journals, and no CONSOLE_HA_REGIONS on the console. - **rootfs:** shop (rootfs, on box-1) shows `process=web` and `process=worker` on every log line since box-1's update. I only read its logs. **Odd things** - **The dev console was not on v0.31.0 before the roll.** It was running a66482c9 (5dcddd46) from 08:07Z. A note at the end of the v0.31.0 roll-log explains it: the plans-6c session moved it there for the billing rehearsal. So I made a66482c9 the rollback target instead of c5fadb15. It wasn't needed. - **Old errors on sophie's journal.** It had "drop-in unreadable (zz-carlos-env.conf)" lines from before this release. They have not come back since the update. - **Already there before this release:** Cost Explorer "AccessDenied" errors when the console starts. The bab account also shows a warning that it is over its plan (4407 of 1500 awake hours). Nothing is left running, and the scratch files I created are removed.</result> <usage><subagent_tokens>151992</subagent_tokens><tool_uses>102</tool_uses><duration_ms>1773647</duration_ms></usage> </task-notification>

Attributed to this commit: 14.8 g CO₂e (1,737,677 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on region-ha-dead-holder-backoff, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

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 1b8e8d667..c71b02ec9 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 now returns a ForwardDecision (Ref, Refuse); a Refuse is answered at the front door with the existing unreachable answer (503, Retry-After: 10, same body, via answerHolderUnreachable), with no forward, no dial, no NoteForward and no per-request step; the Ref path is unchanged. No new read; the same 5 read sites; root never calls it. |
-| `internal/activator/haforward.go` `Service.ForwardTarget` | sites | -registry:Host | Returns edge.ForwardDecision instead of a ref string; the separate holders.get lookup before resolve is folded into holderCache.resolve (one fewer rt.Host site), which now also answers Refuse while the in-memory entry is suspect (a holder that did not answer a forward, for 10 s) with no lock read; after the window the same single bounded (2 s) lock.json read through readHolderView runs as before. 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 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. |
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` → `7e4cd4bc7a5633d701ac57057199d3a614556f1f3a9b794b38c7b8ad2f0920df`.
+Seal: `5b559ba7a42084908cb0fec08083bb2b9b3c9d960036fd10418f81e56304bb64` → `61dc010abf76d6f3a17f9b376935d8c440f53a32ca866923c55a6069ca1dc343`.
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 24e3f67ce..fddda799b 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).
+# CLAIMS for the root-read census, branch region-ha-dead-holder-backoff (region HA P1b-2 follow-up: dead-holder backoff), round 1 fixes.
# Format (AGENTS.md "The census"): <file>:<unit><TAB><what changed>. Lines starting with # are ignored.
-internal/edge/forwardha.go:Edge.frontForwardHA ForwardTarget now returns a ForwardDecision (Ref, Refuse); a Refuse is answered at the front door with the existing unreachable answer (503, Retry-After: 10, same body, via answerHolderUnreachable), with no forward, no dial, no NoteForward and no per-request step; the Ref path is unchanged. No new read; the same 5 read sites; root never calls it.
-internal/activator/haforward.go:Service.ForwardTarget Returns edge.ForwardDecision instead of a ref string; the separate holders.get lookup before resolve is folded into holderCache.resolve (one fewer rt.Host site), which now also answers Refuse while the in-memory entry is suspect (a holder that did not answer a forward, for 10 s) with no lock read; after the window the same single bounded (2 s) lock.json read through readHolderView runs as before. 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 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.
diff --git a/internal/activator/hacache.go b/internal/activator/hacache.go
index 07c070443..edc3c31ab 100644
--- a/internal/activator/hacache.go
+++ b/internal/activator/hacache.go
@@ -5,6 +5,8 @@ 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
@@ -14,9 +16,13 @@ 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. 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.
+// 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
+// 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.
const (
// holderCacheMax bounds the cache; the oldest entry set goes first.
holderCacheMax = 50_000
@@ -31,6 +37,12 @@ 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;
@@ -41,6 +53,7 @@ type holderCache struct {
holders map[string]*list.Element // host -> *holderEntry in order
order list.List // oldest set at the front
flights map[string]*holderFlight // host -> the lock read in flight
+ seq uint64 // the last generation handed out
}
type holderEntry struct {
@@ -48,19 +61,37 @@ 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 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
// the host's entry is set or dropped while the read runs: the read began
-// before that news, so its answer goes to its waiters but is not cached.
-// suspect is the ref of the expired suspect entry the read replaces; a
-// read naming it again refuses its waiters (refuse), and only the caller
-// that read forwards.
+// before that news, so its answer is not cached and its callers look
+// again. suspect is the ref of the expired suspect entry the read
+// replaces: if the read fails, the box stays suspect and every caller is
+// refused (refuse). cached is whether the read's answer was cached.
type holderFlight struct {
done chan struct{}
ref string
suspect string
refuse bool
+ cached bool
stale bool
}
@@ -77,10 +108,6 @@ func (c *holderCache) clock() time.Time {
func (c *holderCache) get(host string) (ref string, positive, found bool) {
c.mu.Lock()
defer c.mu.Unlock()
- return c.getLocked(host)
-}
-
-func (c *holderCache) getLocked(host string) (string, bool, bool) {
el := c.holders[host]
if el == nil {
return "", false, false
@@ -112,40 +139,82 @@ func (c *holderCache) setNegative(host string) {
c.putLocked(host, "", false, holderNegativeTTL)
}
-// suspect marks ref, which did not answer a forward of host's, suspect for
-// holderSuspectTTL, unless host's entry is newer news: a negative entry, or
-// one naming another box. An empty ref drops the entry.
-func (c *holderCache) suspect(host, ref string) {
+// 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.
+func (c *holderCache) unreachable(host string, gen uint64) {
c.mu.Lock()
defer c.mu.Unlock()
- el := c.holders[host]
- if ref == "" {
- if el != nil {
- c.removeLocked(el)
- }
- if f := c.flights[host]; f != nil {
- f.stale = true
- }
- return
+ if e := c.liveLocked(host, gen); e != nil {
+ c.putLocked(host, e.ref, true, holderSuspectTTL)
}
- if el != nil && el.Value.(*holderEntry).ref != ref {
- return
+}
+
+// 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)
+ }
+}
+
+// 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)
}
- c.putLocked(host, ref, true, holderSuspectTTL)
}
// answered follows a forward of host's to ref that came back with an
-// answer: a suspect entry is replaced by ref as the holder. Any other entry
-// stands.
+// 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.
func (c *holderCache) answered(host, ref string) {
if ref == "" {
return
}
c.mu.Lock()
defer c.mu.Unlock()
- if el := c.holders[host]; el != nil && el.Value.(*holderEntry).suspect {
- c.putLocked(host, ref, false, holderPositiveTTL)
+ el := c.holders[host]
+ if el == nil {
+ return
+ }
+ e := el.Value.(*holderEntry)
+ if !e.suspect && e.ref != ref {
+ return
+ }
+ if e.suspect {
+ e = c.putLocked(host, ref, false, holderPositiveTTL)
+ } else {
+ c.seq++
+ e.gen = c.seq
+ e.releaseGate(false)
}
+ e.confirmed = true
}
// drop forgets host's entry, and any read in flight for it.
@@ -160,99 +229,189 @@ func (c *holderCache) drop(host string) {
}
}
-func (c *holderCache) putLocked(host, ref string, suspect bool, ttl time.Duration) {
+// 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 {
if f := c.flights[host]; f != nil {
f.stale = true
}
if c.holders == nil {
c.holders = map[string]*list.Element{}
}
+ c.seq++
expires := c.clock().Add(ttl)
if el := c.holders[host]; el != nil {
e := el.Value.(*holderEntry)
- e.ref, e.suspect, e.expires = ref, suspect, expires
+ e.releaseGate(false)
+ e.ref, e.suspect, e.expires, e.gen, e.confirmed = ref, suspect, expires, c.seq, false
c.order.MoveToBack(el)
- return
+ return e
}
for len(c.holders) >= holderCacheMax {
c.removeLocked(c.order.Front())
}
- c.holders[host] = c.order.PushBack(&holderEntry{host: host, ref: ref, suspect: suspect, expires: expires})
+ e := &holderEntry{host: host, ref: ref, suspect: suspect, expires: expires, gen: c.seq}
+ c.holders[host] = c.order.PushBack(e)
+ return e
}
func (c *holderCache) removeLocked(el *list.Element) {
- delete(c.holders, el.Value.(*holderEntry).host)
+ e := el.Value.(*holderEntry)
+ e.releaseGate(true)
+ delete(c.holders, e.host)
c.order.Remove(el)
}
-// resolve answers a request for host: the holder to forward to, "" 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.
+// 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 that has expired is a miss too, remembered by its
-// flight: when the read names the same box, which may only not have
-// renewed yet, the caller that read forwards to it once more, its waiters
-// are refused, and the box is suspect again until that forward's outcome
-// says otherwise. So a dead holder costs one read and one dial a window.
-func (c *holderCache) resolve(ctx context.Context, host string, read func() (ref string, ok bool)) (string, bool) {
- c.mu.Lock()
- suspect := ""
- if el := c.holders[host]; el != nil {
- e := el.Value.(*holderEntry)
- if c.clock().Before(e.expires) {
- ref, refuse := e.ref, e.suspect
+// - 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.
+func (c *holderCache) resolve(ctx context.Context, host string, read func() (ref string, ok bool)) (string, bool, uint64) {
+ deadline := time.Now().Add(holderReadTimeout + holderConnectWait)
+ 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))
+ c.mu.Unlock()
+ if !waitGate(ctx, g, wait) {
+ return "", true, 0
+ }
+ if g.here {
+ return "", false, 0
+ }
+ continue
+ }
+ if e.suspect {
+ suspect = e.ref
+ }
+ c.removeLocked(el)
+ }
+ if f := c.flights[host]; f != nil {
c.mu.Unlock()
- if refuse {
- return "", true
+ select {
+ case <-f.done:
+ case <-ctx.Done():
+ return "", false, 0
}
- return ref, false
+ if f.refuse {
+ return "", true, 0
+ }
+ if f.cached || f.stale {
+ continue
+ }
+ return f.ref, false, 0
}
- if e.suspect {
- suspect = e.ref
+ f := &holderFlight{done: make(chan struct{}), suspect: suspect}
+ if c.flights == nil {
+ c.flights = map[string]*holderFlight{}
}
- c.removeLocked(el)
- }
- if f := c.flights[host]; f != nil {
+ c.flights[host] = f
c.mu.Unlock()
- select {
- case <-f.done:
- if f.refuse {
- return "", true
- }
- return f.ref, false
- case <-ctx.Done():
- return "", false
+ c.runRead(host, f, read)
+ if f.refuse {
+ return "", true, 0
}
+ if f.cached || f.stale {
+ continue
+ }
+ 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()
+ return "", true, 0
+}
+// runRead runs f's read for host and settles f: its answer cached, unless
+// news arrived while it ran (stale), or kept from caching when it could not
+// tell.
+func (c *holderCache) runRead(host string, f *holderFlight, read func() (string, bool)) {
ref, ok := "", false
defer func() {
c.mu.Lock()
+ // Out of the map first, so the puts below do not mark f stale.
delete(c.flights, host)
- again := ok && ref != "" && ref == f.suspect
- if ok && !f.stale {
- switch {
- case again:
- c.putLocked(host, ref, true, holderSuspectTTL)
- case ref != "":
- c.putLocked(host, ref, false, holderPositiveTTL)
- default:
- c.putLocked(host, "", false, holderNegativeTTL)
- }
+ switch {
+ case f.stale:
+ case ok && ref != "":
+ c.putLocked(host, ref, false, holderPositiveTTL)
+ f.cached = true
+ case ok:
+ c.putLocked(host, "", false, holderNegativeTTL)
+ f.cached = true
+ case f.suspect != "":
+ // A failed read proves no holder gone: the box that did not
+ // answer stays suspect for another window.
+ c.putLocked(host, f.suspect, true, holderSuspectTTL)
+ f.refuse = true
}
- f.ref, f.refuse = ref, again
+ f.ref = ref
c.mu.Unlock()
close(f.done)
}()
ref, ok = read()
- return ref, false
+}
+
+// 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 7c458c508..dbad6b014 100644
--- a/internal/activator/haforward.go
+++ b/internal/activator/haforward.go
@@ -119,7 +119,7 @@ func (a *Service) ForwardTarget(ctx context.Context, rt registry.Route) edge.For
if here {
return edge.ForwardDecision{}
}
- ref, refuse := a.holders.resolve(ctx, rt.Host, func() (string, bool) {
+ ref, refuse, gen := a.holders.resolve(ctx, rt.Host, func() (string, bool) {
// The read is every queued caller's, not only this one's: detached
// from this request's cancellation, so one visitor hanging up does
// not fail the rest, and bounded on its own.
@@ -136,7 +136,7 @@ func (a *Service) ForwardTarget(ctx context.Context, rt registry.Route) edge.For
self, _ := boxSelfRef(a.backend)
return otherHolder(v, self, a.holders.clock()), true
})
- return edge.ForwardDecision{Ref: ref, Refuse: refuse}
+ return edge.ForwardDecision{Ref: ref, Refuse: refuse, Gen: gen}
}
// otherHolder is the box v names as holding the host, when that is an
@@ -158,14 +158,16 @@ func otherHolder(v hafresh.View, self string, now time.Time) string {
// view, an answer of "none", and a 503 that names nobody drop the entry; an
// answer naming a box sets it, unless the box is this one, which drops it
// (this box is never forwarded to). A box that could not be connected to
-// is suspect for holderSuspectTTL, and any other answer from a box clears
-// a suspect entry: that box is the holder.
+// 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.
func (a *Service) NoteForward(host string, res edge.ForwardResult) {
switch {
case res.Outcome == edge.ForwardNotInView:
a.holders.drop(host)
case res.Outcome == edge.ForwardUnreachable:
- a.holders.suspect(host, res.Ref)
+ a.holders.unreachable(host, res.Gen)
case res.Holder == holderNone:
a.holders.drop(host)
case res.Holder != "":
@@ -178,9 +180,18 @@ 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 2ee190b0c..d840c59c7 100644
--- a/internal/activator/haforward_test.go
+++ b/internal/activator/haforward_test.go
@@ -6,7 +6,6 @@ import (
"fmt"
"net/http"
"net/http/httptest"
- "sync"
"sync/atomic"
"testing"
"time"
@@ -51,12 +50,14 @@ func haHeldByB(t *testing.T) *haSvc {
func TestForwardTargetNamesTheHolder(t *testing.T) {
s := haHeldByB(t)
- if got := s.a.ForwardTarget(context.Background(), s.rt).Ref; got != "b" {
- t.Fatalf("ForwardTarget = %q, want b", got)
+ d := s.a.ForwardTarget(context.Background(), s.rt)
+ if d.Ref != "b" {
+ t.Fatalf("ForwardTarget = %+v, want b", d)
}
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)
}
@@ -144,22 +145,20 @@ func TestForwardTargetSingleFlight(t *testing.T) {
return old(ctx, bucket, prefix, region)
}
t.Cleanup(func() { readHolderLock = old })
- var wg sync.WaitGroup
- got := make([]string, 20)
- for i := range got {
- wg.Add(1)
- go func() {
- defer wg.Done()
- got[i] = s.a.ForwardTarget(context.Background(), s.rt).Ref
- }()
- }
+ got := s.concurrently(20)
waitFor(t, "the first read", func() bool { return reads.Load() == 1 })
time.Sleep(50 * time.Millisecond) // the other 19 queue on it
close(gate)
- wg.Wait()
- for i, ref := range got {
- if ref != "b" {
- t.Fatalf("caller %d got %q, want b", i, ref)
+ // 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 {
+ t.Fatalf("caller %d got %+v, want b", i, d)
}
}
if n := reads.Load(); n != 1 {
@@ -403,12 +402,14 @@ func TestScheduledTickNeverForwards(t *testing.T) {
func TestForwardTargetThroughSplitBackend(t *testing.T) {
s := haHeldByB(t)
a := New(Config{Bucket: s.b.Cfg.Bucket, Idle: time.Hour}, &SplitBackend{Exec: s.b, Unit: &UnitBackend{}}, s.b.Registry)
- if got := a.ForwardTarget(context.Background(), s.rt).Ref; got != "b" {
- t.Fatalf("ForwardTarget through the split backend = %q, want b", got)
+ d := a.ForwardTarget(context.Background(), s.rt)
+ if d.Ref != "b" {
+ t.Fatalf("ForwardTarget through the split backend = %+v, want b", d)
}
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 87d1070b9..fab14d1f3 100644
--- a/internal/activator/hasuspect_test.go
+++ b/internal/activator/hasuspect_test.go
@@ -4,7 +4,6 @@ import (
"context"
"net/http"
"net/http/httptest"
- "sync"
"sync/atomic"
"testing"
"time"
@@ -16,8 +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, 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, 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.
// 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
@@ -39,10 +39,53 @@ func (s *haSvc) frontDoor(t *testing.T, forwards *int) string {
return "here"
}
*forwards++
- s.a.NoteForward(s.rt.Host, edge.ForwardResult{Outcome: edge.ForwardUnreachable, Ref: d.Ref})
+ s.a.NoteForward(s.rt.Host, edge.ForwardResult{Outcome: edge.ForwardUnreachable, Ref: d.Ref, Gen: d.Gen})
return "unreachable"
}
+// decide is one ForwardTarget for s's route.
+func (s *haSvc) decide() edge.ForwardDecision {
+ return s.a.ForwardTarget(context.Background(), s.rt)
+}
+
+// note is NoteForward for s's host of a forward decided as d.
+func (s *haSvc) note(d edge.ForwardDecision, res edge.ForwardResult) {
+ res.Ref, res.Gen = d.Ref, d.Gen
+ s.a.NoteForward(s.rt.Host, res)
+}
+
+// concurrently runs n ForwardTargets for s's route at once and returns a
+// channel of their decisions, in the order they return.
+func (s *haSvc) concurrently(n int) <-chan edge.ForwardDecision {
+ out := make(chan edge.ForwardDecision, n)
+ for range n {
+ go func() { out <- s.decide() }()
+ }
+ 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()
+ select {
+ case d := <-ch:
+ return d
+ case <-time.After(10 * time.Second):
+ t.Fatal("a request is still waiting")
+ }
+ return edge.ForwardDecision{}
+}
+
// wokeHere is whether the host has an entry on this box: awake or waking.
func (s *haSvc) wokeHere() bool {
s.a.mu.Lock()
@@ -110,9 +153,8 @@ func TestDeadHolderCostsOneReadAndDialPerWindow(t *testing.T) {
}
}
-// Concurrent requests after the window: one lock read, and only the
-// caller that read forwards; the rest, queued on the read or arriving
-// after it, are refused.
+// 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) {
s, clk := suspectB(t)
clk.advance(holderSuspectTTL + time.Millisecond)
@@ -125,43 +167,241 @@ func TestSuspectWindowEndForwardsOnce(t *testing.T) {
return old(ctx, bucket, prefix, region)
}
t.Cleanup(func() { readHolderLock = old })
- var wg sync.WaitGroup
- got := make([]edge.ForwardDecision, 20)
- for i := range got {
- wg.Add(1)
- go func() {
- defer wg.Done()
- got[i] = s.a.ForwardTarget(context.Background(), s.rt)
- }()
- }
+ got := s.concurrently(20)
waitFor(t, "the read", func() bool { return reads.Load() == 1 })
time.Sleep(50 * time.Millisecond) // the others queue on it
close(gate)
- wg.Wait()
- forwards := 0
- for i, d := range got {
- switch d {
- case edge.ForwardDecision{Ref: "b"}:
- forwards++
- case edge.ForwardDecision{Refuse: true}:
- default:
- t.Fatalf("caller %d: %+v, want b or a refusal", i, d)
+ 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)
}
}
- if forwards != 1 || reads.Load() != 1 {
- t.Fatalf("%d forwards and %d reads for 20 requests after the window, want 1 and 1", forwards, reads.Load())
+ if reads.Load() != 1 {
+ t.Fatalf("%d reads for 20 requests after the window, want 1", reads.Load())
}
- if d := s.a.ForwardTarget(context.Background(), s.rt); !d.Refuse {
- t.Fatalf("while the one forward runs: %+v, want a refusal", d)
+}
+
+// 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)
+ }
+ 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)
}
+ 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)
+ }
+}
+
+// A read that revalidates an expired suspect and fails proves nothing: the
+// window is renewed for the same box and every caller on that read is
+// refused, unless newer news arrived while it ran.
+func TestSuspectRevalidationFailureRenewsTheWindow(t *testing.T) {
+ t.Run("error", func(t *testing.T) {
+ s, clk := suspectB(t)
+ clk.advance(holderSuspectTTL + time.Millisecond)
+ s.fx.FailNext("GET", http.StatusForbidden)
+ forwards := 0
+ if got := s.frontDoor(t, &forwards); got != "refused" {
+ t.Fatalf("a failed revalidation: %s, want refused", got)
+ }
+ reads := lockGets(s.b, s.rt)
+ for i := range 5 {
+ clk.advance(time.Second)
+ if got := s.frontDoor(t, &forwards); got != "refused" {
+ t.Fatalf("request %d of the renewed window: %s, want refused", i, got)
+ }
+ }
+ if n := lockGets(s.b, s.rt); n != reads || forwards != 0 || s.wokeHere() {
+ t.Fatalf("the renewed window: %d more reads, %d forwards, woke here %v; want none", n-reads, forwards, s.wokeHere())
+ }
+ clk.advance(holderSuspectTTL)
+ if got := s.frontDoor(t, &forwards); got != "unreachable" || lockGets(s.b, s.rt) != reads+1 {
+ t.Fatalf("after the renewed window: %s with %d more reads, want unreachable and 1", got, lockGets(s.b, s.rt)-reads)
+ }
+ })
+ t.Run("timeout", func(t *testing.T) {
+ s, clk := suspectB(t)
+ clk.advance(holderSuspectTTL + time.Millisecond)
+ var reads atomic.Int32
+ old := readHolderLock
+ readHolderLock = func(ctx context.Context, _, _, _ string) (hafresh.View, error) {
+ reads.Add(1)
+ <-ctx.Done()
+ return hafresh.View{}, ctx.Err()
+ }
+ t.Cleanup(func() { readHolderLock = old })
+ got := s.concurrently(5)
+ for i := range 5 {
+ if d := recv(t, got); !d.Refuse {
+ t.Fatalf("caller %d on a timed-out revalidation: %+v, want a refusal", i, d)
+ }
+ }
+ if d := s.decide(); !d.Refuse || reads.Load() != 1 {
+ t.Fatalf("within the renewed window: %+v with %d reads, want a refusal and 1", d, reads.Load())
+ }
+ })
+ t.Run("newer news", func(t *testing.T) {
+ s, clk := suspectB(t)
+ clk.advance(holderSuspectTTL + time.Millisecond)
+ 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 })
+ got := s.concurrently(1)
+ waitFor(t, "the read", func() bool { return reads.Load() == 1 })
+ s.a.NoteForward(s.rt.Host, edge.ForwardResult{Outcome: edge.ForwardDone, Ref: "c", Status: 503, Holder: "c"})
+ close(gate)
+ if d := recv(t, got); d.Refuse || d.Ref != "c" {
+ t.Fatalf("a failed read overtaken by X-Carlos-Holder: c: %+v, want a forward to c", d)
+ }
+ })
+}
+
+// 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.
+ 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()
+ if d1.Ref != "b" || d2 != d1 || d3 != d1 {
+ t.Fatalf("decisions %+v %+v %+v, want three to b on one gen", d1, d2, d3)
+ }
+ s.note(d2, edge.ForwardResult{Outcome: edge.ForwardUnreachable})
+ if d := s.decide(); !d.Refuse {
+ t.Fatalf("after d2 failed: %+v, want a refusal", d)
+ }
+ return d1, d2, d3
+ }
+ t.Run("same-ref success", func(t *testing.T) {
+ s := haHeldByB(t)
+ d1, _, d3 := outstanding(t, s)
+ s.note(d1, edge.ForwardResult{Outcome: edge.ForwardDone, Status: http.StatusOK})
+ s.note(d3, edge.ForwardResult{Outcome: edge.ForwardUnreachable})
+ if d := s.decide(); d.Refuse || d.Ref != "b" {
+ t.Fatalf("an older failure after b answered: %+v, want a forward to b", d)
+ }
+ })
+ t.Run("holder header", func(t *testing.T) {
+ s := haHeldByB(t)
+ d1, _, d3 := outstanding(t, s)
+ s.note(d1, edge.ForwardResult{Outcome: edge.ForwardDone, Status: 503, Holder: "b"})
+ s.note(d3, edge.ForwardResult{Outcome: edge.ForwardUnreachable})
+ if d := s.decide(); d.Refuse || d.Ref != "b" {
+ t.Fatalf("an older failure after X-Carlos-Holder: b: %+v, want a forward to b", d)
+ }
+ })
+ t.Run("lease acquisition", func(t *testing.T) {
+ s := haService(t, "shop.example.com")
+ s.rt.HA = true
+ s.a.holders.set(s.rt.Host, "b")
+ d := s.decide()
+ if d.Ref != "b" {
+ t.Fatalf("decision %+v, want b", d)
+ }
+ if _, err := s.wakeForTest(context.Background()); err != nil {
+ t.Fatalf("wake: %v", err)
+ }
+ s.note(d, edge.ForwardResult{Outcome: edge.ForwardUnreachable})
+ if _, _, found := s.a.holders.get(s.rt.Host); found {
+ t.Fatal("an older failure made b suspect after this box took the lease")
+ }
+ })
}
func TestSuspectClearedByTakingTheLease(t *testing.T) {
s := haService(t, "shop.example.com")
s.rt.HA = true
s.a.holders.set(s.rt.Host, "b")
- s.a.NoteForward(s.rt.Host, edge.ForwardResult{Outcome: edge.ForwardUnreachable, Ref: "b"})
- if d := s.a.ForwardTarget(context.Background(), s.rt); !d.Refuse {
+ s.note(s.decide(), edge.ForwardResult{Outcome: edge.ForwardUnreachable})
+ if d := s.decide(); !d.Refuse {
t.Fatalf("a suspect holder: %+v, want a refusal", d)
}
e, err := s.wakeForTest(context.Background())
@@ -181,7 +421,7 @@ func TestSuspectClearedByAHolderHeader(t *testing.T) {
host := s.rt.Host
// Another box's answer names c: c is the holder, no read needed.
s.a.NoteForward(host, edge.ForwardResult{Outcome: edge.ForwardDone, Ref: "c", Status: 503, Holder: "c"})
- if d := s.a.ForwardTarget(context.Background(), s.rt); d != (edge.ForwardDecision{Ref: "c"}) || lockGets(s.b, s.rt) != 1 {
+ if d := s.decide(); d.Ref != "c" || d.Refuse || lockGets(s.b, s.rt) != 1 {
t.Fatalf("after X-Carlos-Holder: c: %+v with %d reads, want c and 1", d, lockGets(s.b, s.rt))
}
@@ -198,7 +438,7 @@ func TestSuspectClearedByASuccessfulForward(t *testing.T) {
s, _ := suspectB(t)
// A forward begun before b went suspect comes back answered.
s.a.NoteForward(s.rt.Host, edge.ForwardResult{Outcome: edge.ForwardDone, Ref: ref, Status: http.StatusOK})
- if d := s.a.ForwardTarget(context.Background(), s.rt); d != (edge.ForwardDecision{Ref: ref}) || lockGets(s.b, s.rt) != 1 {
+ if d := s.decide(); d.Ref != ref || d.Refuse || lockGets(s.b, s.rt) != 1 {
t.Fatalf("after %s answered: %+v with %d reads, want %s and 1", ref, d, lockGets(s.b, s.rt), ref)
}
}
@@ -216,7 +456,7 @@ func TestUnreachableKeepsNewerNews(t *testing.T) {
s := haHeldByB(t)
s.a.holders.set(s.rt.Host, "c")
s.a.NoteForward(s.rt.Host, edge.ForwardResult{Outcome: edge.ForwardUnreachable, Ref: "b"})
- if d := s.a.ForwardTarget(context.Background(), s.rt); d != (edge.ForwardDecision{Ref: "c"}) {
+ if d := s.decide(); d.Ref != "c" || d.Refuse {
t.Fatalf("an old forward to b failed after c was named: %+v, want c", d)
}
s.a.holders.setNegative(s.rt.Host)
diff --git a/internal/edge/forwardha.go b/internal/edge/forwardha.go
index 56f3179a3..fa7e0e8b2 100644
--- a/internal/edge/forwardha.go
+++ b/internal/edge/forwardha.go
@@ -22,6 +22,8 @@ import (
"fmt"
"net"
"net/http"
+ "net/http/httptrace"
+ "sync"
"time"
"github.com/carlosframework/platform/internal/registry"
@@ -32,11 +34,15 @@ 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. NoteForward reports how a
-// forward went, so the activator's holder cache can follow it. 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. 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.
type HAForwarder interface {
ForwardTarget(ctx context.Context, rt registry.Route) ForwardDecision
+ NoteConnected(host string, gen uint64)
NoteForward(host string, res ForwardResult)
}
@@ -49,6 +55,9 @@ 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 uint64
}
// ForwardOutcome is how one forward ended.
@@ -67,13 +76,14 @@ const (
ForwardDone
)
-// ForwardResult is what NoteForward is told. Ref is the box the request was
-// sent to (ForwardDecision.Ref). Status is the upstream's status, 0 when no
+// ForwardResult is what NoteForward is told. Ref and Gen are the decision's:
+// the box the request was sent to and the activator's token. Status is the upstream's status, 0 when no
// answer came back from it (a hop this box refused, or a failure after
// connecting). Holder is the upstream's X-Carlos-Holder, "" when absent.
type ForwardResult struct {
Outcome ForwardOutcome
Ref string
+ Gen uint64
Status int
Holder string
}
@@ -106,6 +116,10 @@ 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.
@@ -128,7 +142,8 @@ 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
-// how it went, and it is answered unless the box was not in view.
+// when its connection is made and 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
@@ -148,34 +163,46 @@ func (e *Edge) frontForwardHA(w http.ResponseWriter, r *http.Request, host strin
if d.Ref == "" {
return false
}
- res := e.forwardHA(w, r, host, d.Ref)
- fw.NoteForward(up.route.Host, res)
+ routeHost := up.route.Host
+ res := e.forwardHA(w, r, host, d, func() { fw.NoteConnected(routeHost, d.Gen) })
+ fw.NoteForward(routeHost, res)
return res.Outcome != ForwardNotInView
}
-// forwardHA sends r to the box labelled 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 ref. A failure to connect is answered 503,
-// Retry-After: 10; every other answer is the holder's, relayed as is.
+// 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.
//
// 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, ref string) ForwardResult {
+func (e *Edge) forwardHA(w http.ResponseWriter, r *http.Request, host string, d ForwardDecision, connected func()) ForwardResult {
+ ref := d.Ref
+ res := ForwardResult{Outcome: ForwardNotInView, Ref: ref, Gen: d.Gen}
m := e.homes.Load()
if m == nil || hopVerified(r.Context()) {
- return ForwardResult{Outcome: ForwardNotInView, Ref: ref}
+ return res
}
dial, ok := m.boxInView(ref, time.Now())
if !ok {
- return ForwardResult{Outcome: ForwardNotInView, Ref: ref}
+ return res
}
key := signingKey(m.meshKeys())
if len(key) == 0 {
e.logThrottled("forward-no-mesh-key", fmt.Sprintf("%s is held on %s but no mesh key is mirrored; serving here", host, ref))
- return ForwardResult{Outcome: ForwardNotInView, Ref: ref}
+ 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) },
+ }))
}
- res := ForwardResult{Outcome: ForwardDone, Ref: ref}
onError := func(w http.ResponseWriter, r *http.Request, err error) {
var connect *forwardConnectError
if errors.As(err, &connect) && r.Context().Err() == nil {
diff --git a/internal/edge/forwardha_test.go b/internal/edge/forwardha_test.go
index a1a2d0c7d..b9315ad79 100644
--- a/internal/edge/forwardha_test.go
+++ b/internal/edge/forwardha_test.go
@@ -62,11 +62,18 @@ 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
- asked atomic.Int64
- mu sync.Mutex
- notes []fwNote
+ target string
+ refuse bool
+ gen uint64
+ asked atomic.Int64
+ mu sync.Mutex
+ notes []fwNote
+ connects []fwConnect
+}
+
+type fwConnect struct {
+ host string
+ gen uint64
}
type fwNote struct {
@@ -91,7 +98,18 @@ func (a *fwAct) ServeHTTP(w http.ResponseWriter, r *http.Request, _ registry.Rou
func (a *fwAct) RetireExcept(map[string]bool) {}
func (a *fwAct) ForwardTarget(_ context.Context, _ registry.Route) ForwardDecision {
a.asked.Add(1)
- return ForwardDecision{Ref: a.target, Refuse: a.refuse}
+ 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()
@@ -654,8 +672,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 := x.aAct.noted(); len(notes) != 0 {
- t.Fatalf("notes = %+v, want none: nothing was forwarded", notes)
+ 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 got := x.aAct.asked.Load(); got != int64(len(cases)) {
t.Fatalf("annie asked its activator %d times, want %d", got, len(cases))
@@ -668,6 +686,38 @@ 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) {
+ 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)
+ }
+}
+
func TestForwardHAHolderLostHost(t *testing.T) {
x := newFwScene(t, fwOpts{bettyLacks: true})
resp, body := x.fetch(t, fwHost, "/")
@@ -850,6 +900,9 @@ 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/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 5ba38000b..f177e774d 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 7e4cd4bc7a5633d701ac57057199d3a614556f1f3a9b794b38c7b8ad2f0920df
+plan14-root-reads-region-ha-dead-holder-backoff.tsv 61dc010abf76d6f3a17f9b376935d8c440f53a32ca866923c55a6069ca1dc343
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 092f034ee..7dad283bb 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 c2dd6d1295b5358ceef8f50d52b4448ea7a419d1cac8e8c6991927bc0100af04 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 now returns a ForwardDecision (Ref, Refuse); a Refuse is answered at the front door with the existing unreachable answer (503, Retry-After: 10, same body, via answerHolderUnreachable), with no forward, no dial, no NoteForward and no per-request step; the Ref path is unchanged. No new read; the same 5 read sites; root never calls it. registry:HA@225,registry:Host@567,whole:Route@228,whole:Route@405,whole:Route@570 afc079f9a7dcb7369a1d3c88a42feb1304ecde697684c91bde0ecddd1ec276a1
-@legacy feb21c2afaddb5a44c0a7c259b6e1465a7df92ec9f73d291e4233136ef2403db 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 instead of a ref string; the separate holders.get lookup before resolve is folded into holderCache.resolve (one fewer rt.Host site), which now also answers Refuse while the in-memory entry is suspect (a holder that did not answer a forward, for 10 s) with no lock read; after the window the same single bounded (2 s) lock.json read through readHolderView runs as before. No new read and no new S3 request; root never calls it. registry:HA@100,registry:Host@262,registry:Host@378,registry:Host@995,whole:Route@176,whole:Route@736 735734490e0a5509c067719fe31bd02c8a62abf855cdb44da72c285a6cb59f37
-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 now returns a ForwardDecision (Ref, Refuse); a Refuse is answered at the front door with the existing unreachable answer (503, Retry-After: 10, same body, via answerHolderUnreachable), with no forward, no dial, no NoteForward and no per-request step; the Ref path is unchanged. No new read; the same 5 read sites; root never calls it. registry:HA@225,registry:Host@567,whole:Route@228,whole:Route@405,whole:Route@570 afc079f9a7dcb7369a1d3c88a42feb1304ecde697684c91bde0ecddd1ec276a1
-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 instead of a ref string; the separate holders.get lookup before resolve is folded into holderCache.resolve (one fewer rt.Host site), which now also answers Refuse while the in-memory entry is suspect (a holder that did not answer a forward, for 10 s) with no lock read; after the window the same single bounded (2 s) lock.json read through readHolderView runs as before. No new read and no new S3 request; root never calls it. registry:HA@100,registry:Host@262,registry:Host@378,registry:Host@995,whole:Route@176,whole:Route@736 735734490e0a5509c067719fe31bd02c8a62abf855cdb44da72c285a6cb59f37
-@coverage internal/activator 50c264d416235d04877e4057962db4200fc1c83533df7687ccb30767d2547494
-@coverage internal/edge 65da495d04961a34d9c83d72a96956c154072d147dc612094399a25554f769a4
+@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