edge: fix HTTP/2 holder follows and hint invalidation
Use request framing to recognize empty HTTP/2 requests. Preserve holder hints on client cancellation and drop them on TCP or TLS connection failure. Add per-box throttled follow and hint diagnostics. Cover HTTP/2 GET/HEAD, cancellation, and TLS failure through real edges; verify the HTTP/2 and cancellation regressions with mutations.
Implemented-by: Astra (codex)
internal/edge/backhaul_holder.go+43 −8internal/edge/backhaul_holder_export_test.go+70 −0internal/edge/backhaul_holder_wiring_test.go+48 −13
Intent
<task-notification> <task-id>a64bb7757a40205b7</task-id> <tool-use-id>toolu_014TLZ441JYhyd4ZFtzhBPih</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/87a21814-5655-4016-9e7e-41935ee8e96e/tasks/a64bb7757a40205b7.output</output-file> <status>completed</status> <summary>Agent "Review Task 2 W4 holder follow" 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>**Task 2 review (W4, 68082f7b..445e881d)** **Spec compliance: ❌.** The design and safety properties are right, but the follow almost never happens for real browser traffic (Critical 1). **Critical** 1. `internal/edge/backhaul_holder.go:123`: the "no body" check also requires `r.Body == nil || r.Body == http.NoBody`. HTTP/2 requests never pass it. - The public HTTPS server is built from `autocert.Manager.TLSConfig()` (`edge.go:4702`) and started with `ServeTLS` (`edge.go:~4827`). That config offers `h2`, so browsers connect over HTTP/2. - Go's HTTP/2 server sets every request's `Body` to its own `http2requestBody`, even a bodyless GET (`h2_bundle.go` `newWriterAndRequestNoBody`). It is never `http.NoBody`. - So for every HTTP/2 GET or HEAD, `noBody` is false. Dennis relays the first box's `503 Retry-After: 1` exactly as before, which is the W4 symptom. It only remembers the holder for the next request. - The tests miss this because the fixture client (`e2eClientFor`) speaks HTTP/1.1. - Fix: drop the `Body` identity test and use `r.ContentLength == 0 && len(r.TransferEncoding) == 0`. Both HTTP/1 and HTTP/2 set `ContentLength` 0 only when there is no body. Then add one HTTP/2 client case to `TestBackhaulFollowsHolderOnce`, for example an `http.Transport` with `ForceAttemptHTTP2`. **Important** - None beyond the above. **Minor** - `backhaul_holder.go:134-141` (`onError`): any proxy error drops the hint and logs `backhaul-error`, including a client hanging up mid-request. That is harmless, since it only causes relearning and the log is throttled per box. But the brief said "dial failure". - No log line or counter records a follow or a learned hint. Seeing one would make the G2 rerun witness easier to read. There is no spam risk either way. - In most tests the holder edge (betty) serves a plain service route with no activator. Its lease re-check is only exercised in `HolderActivator`, the holder's-own-503 case. Production behaviour on the holder side is unchanged, so this is acceptable. - If a remembered holder fails to dial, the request gets a 502 and does not fall back to the home box. The report hands that fallback to Task 3. It is documented and the hint is dropped, so only the one request fails. **Checked and correct** - **Single writer:** the follow only routes the request. The holder's edge and activator still decide who serves. `boxInView` is untouched. The new `boxInRegionView` (`holderview.go:66-96`) compares the holder with the dialed box's file: same Region and Placement, neither placement null, the same non-empty DataBucket and SecretsKeyFP, `HomeEligible`, and a fresh, parseable generation. It refuses `none`, an empty ref and the sender itself. - **Hop count:** at most two attempts. The second call passes `follow=false` (`:144`), and the holder's 503 then goes to the normal proxy path and is relayed. `ref == box` is never followed. - **First 503 never reaches the client:** the transport returns a sentinel error after `resp.Body.Close()` (`:99-101`). The ErrorHandler writes nothing for that sentinel, and ReverseProxy has written no headers yet. The first hop's capacity slot is released before the second hop starts. Retry-After is dropped on a follow and the holder's own value is relayed when it answers 503. - **Header trust:** the hint comes only from the TLS-verified, signed response of the box we dialed. On that box, an app's header and trailers are removed by `stripAppHolder` in `responseModifier`, including on non-HA routes. Edge admission refusals delete the header (`group_admission.go:32`), and static `_headers` is an allowlist. Even a spoofed name can only point inside the validated pool, and that box re-checks the lease. A 503 naming someone else or `none` heals the memory. The test `TestBackhaulAppHolderCannotSteer` covers this. - **Memory:** one mutex guards the map and the eviction list. The cap is 50k and the TTL is ten minutes. Every hit is re-validated against the view. `drop(host, ref)` removes an entry only if it still names that holder, so an old holder's failure cannot evict a replacement. `nextDial` and `nextRef` are written inside `RoundTrip`, which runs synchronously within `ServeHTTP`, so there is no race. - **Upgrades:** a 101 passes through the normal proxy path, and the upgrade test passes. Body-bearing upgrades are refused, which is conservative and acceptable. **⚠️ Cannot verify from diff** - Freshness uses `HeadroomFresh`, which allows 15 minutes. A pool box's generation only advances because timed passes rewrite the file when it carries headroom (`edgesfile.go:1012`, `state.timed()`). If production pool boxes publish no headroom, or the timed cadence is over 15 minutes, holders are silently never followed. This fails closed, so it is not a safety risk. Confirm the cadence on dev during the rerun. - I did not check whether other front-door paths, such as the form gate around `edge.go:2286`, wrap `r.Body` before backhaul. The fix for Critical 1 makes that irrelevant. I ran no tests. The HTTP/2 finding comes from reading the Go standard library source plus the edge's TLS config. **Task quality: Not approved.** One small fix is needed (Critical 1) plus an HTTP/2 test case. Everything else is sound.</result> <usage><subagent_tokens>82807</subagent_tokens><tool_uses>27</tool_uses><duration_ms>195033</duration_ms></usage> </task-notification>
<task-notification> <task-id>b7hhudtkw</task-id> <tool-use-id>toolu_01P3f3msbVvp4RZ9GXJXVFo1</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/87a21814-5655-4016-9e7e-41935ee8e96e/tasks/b7hhudtkw.output</output-file> <status>completed</status> <summary>Background command "W=/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g2r-fixes/.superpowers/sdd/2026-11-06-region-ha-g2r-fixes; for i in $(seq 1 340); do [ -f $W/t4f1.done ] && break; sleep 10; done; cat $W/t4f1.done 2>/dev/null; tail -2 $W/t4f1.log" completed (exit code 0)</summary> </task-notification>
<task-notification> <task-id>a98f522c84aaec7ff</task-id> <tool-use-id>toolu_01FSKERfB1D6wJBGHC6WMGey</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/87a21814-5655-4016-9e7e-41935ee8e96e/tasks/a98f522c84aaec7ff.output</output-file> <status>completed</status> <summary>Agent "Re-review Task 4 fix round 1" 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>**Task 4 fix round 1 (a5ecbe76) re-review** All four findings are addressed, and I found no Critical or Important new breakage. I could not run the tests myself: the sandbox has the Go build cache read-only, so `go test` failed at setup. The test results below are from the implementer's report. **Findings** 1. **ADDRESSED.** - `internal/host/changeindex.go:208-210`: one global 60 s spacing between early rounds, checked in `eligible`. - Per-evidence cap of three: `!starts[0].After(observed)` at `changeindex.go:209`, with the start times rotated in `begin` at `:240`. A round started before a departure's evidence does not count against that departure. - Once the three rounds are used, the departure waits for the regular backstop. Early rounds never reset the backstop timer (`:173-174`). - The cost comment is corrected at `:244-253`. 2. **ADDRESSED.** - `requestDepartureInventory` (`:253-255`) only takes a short mutex and does a non-blocking send on a channel that holds one signal, so requests coalesce. - The walk runs in `recordViewBackstopLoop` (`:168-171`) under the agent-lifetime context, so `scanMu` is no longer held across the walk. - `hadepartures_scan.go:542-547` keeps only the hook call. 3. **ADDRESSED.** The `inventoryRequests` map and the delete in `complete` are removed (`hadepartures.go:100-104`, `hadepartures_scan.go:531`). The limiter is now fixed-size state that does not depend on departure IDs. 4. **ADDRESSED.** - Step deadline does not degrade the view or block `scanMu`: `TestDepartureInventoryNudgeStepDeadline`. - Twelve stuck departures cause at most three rebuilds, including failed walks: `TestDepartureInventoryNudgeGlobalBudget`. - Coalescing, the 0-1200 s rate limit, and the unindexed path are also tested. - A genuine storage failure still marks the view incomplete. That is the existing `Rebuild` contract and is correct. **Binding constraints** - **I3 holds.** `FreshAfter(d.ObservedAt)` still gates both scan (`hadepartures_scan.go:138`) and `complete` (`:436`). - **No contract change.** `Refresh` and `SourceReadStartedAt` are untouched. - **No new steady-state polling.** With a nil view, `tick` stays nil and the loop only waits for a wake or cancellation (`changeindex.go:156-176`). **New breakage check** - **Concurrency and deadlock: none.** `nudger.mu` is only ever the innermost lock, held briefly while `scanMu` is held, and the send never blocks. The rebuild serializes with `Refresh` on the view mutex, which the backstop already did before this change. - **Goroutine leaks: none.** The loop exits on `agentCtx`. The timer is stopped by `defer` and reset only after it fires. - **`agent.go:1010`, loop running without a RecordView:** safe. With a nil view the loop sets `backstopFullDue`, which the fast loop consumes (`agent.go:3240`, clamp 5 s). This loop now also runs on fleet and unindexed boxes but stays idle without departure evidence. Early requests made during `runHAIngressStartup` are buffered (one slot) and are not lost. - **Test flakiness:** low. The rig saves and restores the global nudger and `backstopFullDue`, and drains the round that runs at loop start (`hadepartures_inventory_test.go:26-28, 63-81`). The loop goroutine is joined before the global nudger is restored (`:319`). Waits poll with 3 s deadlines, not fixed sleeps. **Minor (not blocking)** - `changeindex.go:233-241`: if a walk takes longer than 60 s, a request accepted during it starts a second round as soon as it finishes. `pending` only keeps the newest observation time, so that round can re-cover evidence the first walk already handled, using one of its three attempts. It stays within the cap and the 60 s spacing. All addressed: yes</result> <usage><subagent_tokens>58164</subagent_tokens><tool_uses>8</tool_uses><duration_ms>86292</duration_ms></usage> </task-notification>
Attributed to this commit: 4.86 g CO₂e (597,582 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on region-ha-g2r-fixes, 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/internal/edge/backhaul_holder.go b/internal/edge/backhaul_holder.go| index c66cb65e5..cb33855db 100644 |
| --- a/internal/edge/backhaul_holder.go |
| +++ b/internal/edge/backhaul_holder.go |
| @@ -2,10 +2,13 @@ package edge |
| import ( |
| "container/list" |
| + "crypto/tls" |
| "errors" |
| "fmt" |
| "net/http" |
| + "net/http/httptrace" |
| "sync" |
| + "sync/atomic" |
| "time" |
| ) |
| @@ -39,7 +42,7 @@ func (c *backhaulHolderCache) get(host string, now time.Time) string { |
| return entry.ref |
| } |
| -func (c *backhaulHolderCache) remember(host, ref string, now time.Time) { |
| +func (c *backhaulHolderCache) remember(host, ref string, now time.Time) bool { |
| c.mu.Lock() |
| defer c.mu.Unlock() |
| if c.entries == nil { |
| @@ -47,9 +50,10 @@ func (c *backhaulHolderCache) remember(host, ref string, now time.Time) { |
| } |
| entry := backhaulHolderEntry{host: host, ref: ref, until: now.Add(backhaulHolderTTL)} |
| if el := c.entries[host]; el != nil { |
| + changed := el.Value.(backhaulHolderEntry).ref != ref |
| el.Value = entry |
| c.order.MoveToBack(el) |
| - return |
| + return changed |
| } |
| if len(c.entries) >= backhaulHolderLimit { |
| el := c.order.Front() |
| @@ -57,14 +61,23 @@ func (c *backhaulHolderCache) remember(host, ref string, now time.Time) { |
| c.order.Remove(el) |
| } |
| c.entries[host] = c.order.PushBack(entry) |
| + return true |
| } |
| -func (c *backhaulHolderCache) drop(host, ref string) { |
| +func (c *backhaulHolderCache) drop(host, ref string) bool { |
| c.mu.Lock() |
| defer c.mu.Unlock() |
| if el := c.entries[host]; el != nil && el.Value.(backhaulHolderEntry).ref == ref { |
| delete(c.entries, host) |
| c.order.Remove(el) |
| + return true |
| + } |
| + return false |
| +} |
| + |
| +func (e *Edge) dropBackhaulHolder(host, ref, reason string) { |
| + if e.backhaulHolders.drop(host, ref) { |
| + e.logThrottled("backhaul-holder-drop "+ref, fmt.Sprintf("backhaul holder dropped for %s: %s (%s)", host, ref, reason)) |
| } |
| } |
| @@ -76,7 +89,7 @@ func (e *Edge) backhaulTarget(host, dial, box string) (string, string) { |
| if addr, ok := e.homes.Load().boxInRegionView(ref, box, now); ok { |
| return addr, ref |
| } |
| - e.backhaulHolders.drop(host, ref) |
| + e.dropBackhaulHolder(host, ref, "left region view") |
| } |
| return dial, box |
| } |
| @@ -105,13 +118,29 @@ func (t backhaulHolderTransport) RoundTrip(r *http.Request) (*http.Response, err |
| func (e *Edge) backhaulAttempt(w http.ResponseWriter, r *http.Request, host, dial, box string, key []byte, follow bool) { |
| var nextDial, nextRef string |
| + // Only connection failures disprove a hint. A canceled client or an |
| + // error after connecting says nothing about which box holds the lease. |
| + var connectFailed atomic.Bool |
| + r = r.WithContext(httptrace.WithClientTrace(r.Context(), &httptrace.ClientTrace{ |
| + GotConn: func(httptrace.GotConnInfo) { connectFailed.Store(false) }, |
| + ConnectDone: func(_, _ string, err error) { |
| + if err != nil { |
| + connectFailed.Store(true) |
| + } |
| + }, |
| + TLSHandshakeDone: func(_ tls.ConnectionState, err error) { |
| + if err != nil { |
| + connectFailed.Store(true) |
| + } |
| + }, |
| + })) |
| tr := backhaulHolderTransport{RoundTripper: e.backhaulTransport(dial), response: func(resp *http.Response) error { |
| if resp.StatusCode != http.StatusServiceUnavailable { |
| return nil |
| } |
| ref := resp.Header.Get(holderHeader) |
| if ref != box { |
| - e.backhaulHolders.drop(host, box) |
| + e.dropBackhaulHolder(host, box, "holder refusal") |
| } |
| if ref == "" || ref == "none" || ref == box { |
| return nil |
| @@ -121,8 +150,11 @@ func (e *Edge) backhaulAttempt(w http.ResponseWriter, r *http.Request, host, dia |
| if !ok { |
| return nil |
| } |
| - e.backhaulHolders.remember(host, ref, now) |
| - noBody := (r.Body == nil || r.Body == http.NoBody) && r.ContentLength == 0 && len(r.TransferEncoding) == 0 |
| + if e.backhaulHolders.remember(host, ref, now) { |
| + e.logThrottled("backhaul-holder-learn "+ref, fmt.Sprintf("backhaul holder learned for %s: %s", host, ref)) |
| + } |
| + // HTTP/2 supplies a body object even when the request has no body. |
| + noBody := r.ContentLength == 0 && len(r.TransferEncoding) == 0 |
| if follow && noBody && (r.Method == http.MethodGet || r.Method == http.MethodHead || isUpgradeRequest(r)) { |
| nextDial, nextRef = addr, ref |
| return errBackhaulHolder |
| @@ -133,7 +165,9 @@ func (e *Edge) backhaulAttempt(w http.ResponseWriter, r *http.Request, host, dia |
| if errors.Is(err, errBackhaulHolder) { |
| return |
| } |
| - e.backhaulHolders.drop(host, box) |
| + if connectFailed.Load() && r.Context().Err() == nil { |
| + e.dropBackhaulHolder(host, box, "connect failure") |
| + } |
| e.logThrottled("backhaul-error "+box, fmt.Sprintf("backhaul %s to %s (%s): %v", host, box, dial, err)) |
| w.WriteHeader(http.StatusBadGateway) |
| } |
| @@ -141,6 +175,7 @@ func (e *Edge) backhaulAttempt(w http.ResponseWriter, r *http.Request, host, dia |
| // The refused hop releases its capacity slot before the holder starts a |
| // response that may stream or remain upgraded indefinitely. |
| if nextRef != "" { |
| + e.logThrottled("backhaul-holder-follow "+nextRef, fmt.Sprintf("backhaul following holder for %s: %s to %s", host, box, nextRef)) |
| e.backhaulAttempt(w, r, host, nextDial, nextRef, key, false) |
| } |
| } |
diff --git a/internal/edge/backhaul_holder_export_test.go b/internal/edge/backhaul_holder_export_test.go| index f7546cddf..7e80903dd 100644 |
| --- a/internal/edge/backhaul_holder_export_test.go |
| +++ b/internal/edge/backhaul_holder_export_test.go |
| @@ -4,6 +4,7 @@ import ( |
| "bufio" |
| "context" |
| "crypto/tls" |
| + "crypto/x509" |
| "encoding/json" |
| "fmt" |
| "io" |
| @@ -21,6 +22,8 @@ import ( |
| type BackhaulHolderScene struct { |
| sender, first, holder *backhaulEdge |
| store release.Store |
| + app *fwAppServer |
| + http2 bool |
| } |
| func NewBackhaulHolderScene(t *testing.T, bucket string, act Activator, rt registry.Route) *BackhaulHolderScene { |
| @@ -35,6 +38,7 @@ func NewBackhaulHolderScene(t *testing.T, bucket string, act Activator, rt regis |
| } |
| s.first = newBackhaulEdgeWith(t, bucket, "annie", ca, nil, act, []registry.Route{rt}) |
| app := fwApp(t, "holder") |
| + s.app = app |
| s.holder = newBackhaulEdge(t, bucket, "betty", ca, nil, map[string]string{rt.Host: app.srv.Listener.Addr().String()}) |
| s.sender = newBackhaulEdge(t, bucket, "dennis", ca, nil, nil) |
| old := backhaulRootCAs |
| @@ -75,6 +79,9 @@ func (s *BackhaulHolderScene) Request(t *testing.T, method, path, body string) ( |
| t.Fatal(err) |
| } |
| defer resp.Body.Close() |
| + if s.http2 && resp.ProtoMajor != 2 { |
| + t.Fatalf("protocol=%s, want HTTP/2", resp.Proto) |
| + } |
| b, err := io.ReadAll(resp.Body) |
| if err != nil { |
| t.Fatal(err) |
| @@ -123,6 +130,13 @@ func (s *BackhaulHolderScene) HolderDown() { |
| s.sender.edge.backhaulTransport("127.0.0.2").CloseIdleConnections() |
| } |
| +func (s *BackhaulHolderScene) HolderTLSFailure() { |
| + tr := s.sender.edge.backhaulTransport("127.0.0.2") |
| + tr.CloseIdleConnections() |
| + tr.TLSClientConfig = tr.TLSClientConfig.Clone() |
| + tr.TLSClientConfig.RootCAs = x509.NewCertPool() |
| +} |
| + |
| func (s *BackhaulHolderScene) FirstApp(t *testing.T) { |
| t.Helper() |
| app := fwApp(t, "first") |
| @@ -175,3 +189,59 @@ func (s *BackhaulHolderScene) ExpireMemory() { |
| el.Value = entry |
| } |
| } |
| + |
| +func (s *BackhaulHolderScene) UseHTTP2(t *testing.T) { |
| + t.Helper() |
| + tr := &http.Transport{ |
| + ForceAttemptHTTP2: true, |
| + TLSClientConfig: &tls.Config{RootCAs: backhaulRootCAs, MinVersion: tls.VersionTLS12}, |
| + DialContext: func(ctx context.Context, network, _ string) (net.Conn, error) { |
| + var d net.Dialer |
| + return d.DialContext(ctx, network, s.sender.tlsAddr) |
| + }, |
| + } |
| + t.Cleanup(tr.CloseIdleConnections) |
| + s.sender.client = &http.Client{Transport: tr, Timeout: 10 * time.Second} |
| + s.http2 = true |
| +} |
| + |
| +func (s *BackhaulHolderScene) CancelHeldRequest(t *testing.T) { |
| + t.Helper() |
| + defer s.app.release() |
| + ctx, cancel := context.WithCancel(t.Context()) |
| + defer cancel() |
| + req, err := http.NewRequestWithContext(ctx, "GET", "https://"+HAForwardHost+"/assets/held.js", nil) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + served := s.sender.calls.Load() + 1 |
| + done := make(chan error, 1) |
| + go func() { |
| + resp, err := s.sender.client.Do(req) |
| + if resp != nil { |
| + resp.Body.Close() |
| + } |
| + done <- err |
| + }() |
| + select { |
| + case <-s.app.started: |
| + case <-time.After(5 * time.Second): |
| + t.Fatal("holder app did not receive the request") |
| + } |
| + cancel() |
| + select { |
| + case err := <-done: |
| + if err == nil { |
| + t.Fatal("canceled request succeeded") |
| + } |
| + case <-time.After(5 * time.Second): |
| + t.Fatal("canceled client did not return") |
| + } |
| + deadline := time.Now().Add(5 * time.Second) |
| + for s.sender.served.Load() < served { |
| + if time.Now().After(deadline) { |
| + t.Fatal("sender did not finish the canceled request") |
| + } |
| + time.Sleep(time.Millisecond) |
| + } |
| +} |
diff --git a/internal/edge/backhaul_holder_wiring_test.go b/internal/edge/backhaul_holder_wiring_test.go| index 03c0bb359..264602913 100644 |
| --- a/internal/edge/backhaul_holder_wiring_test.go |
| +++ b/internal/edge/backhaul_holder_wiring_test.go |
| @@ -68,21 +68,54 @@ func backhaulHeldService(t *testing.T, holder string) (*activator.Service, regis |
| } |
| func TestBackhaulFollowsHolderOnce(t *testing.T) { |
| + for _, tc := range []struct { |
| + name, method string |
| + http2 bool |
| + }{ |
| + {"http1 GET", "GET", false}, |
| + {"http2 GET", "GET", true}, |
| + {"http2 HEAD", "HEAD", true}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + svc, rt, bucket, _ := backhaulHeldService(t, "betty") |
| + s := edge.NewBackhaulHolderScene(t, bucket, svc, rt) |
| + if tc.http2 { |
| + s.UseHTTP2(t) |
| + } |
| + status, headers, body := s.Request(t, tc.method, "/", "") |
| + wantBody := "holder|" + rt.Host + "|/" |
| + if tc.method == "HEAD" { |
| + wantBody = "" |
| + } |
| + if status != 200 || body != wantBody || headers.Get("Retry-After") != "" { |
| + t.Fatalf("%s: %d %v %q; want holder's 200", tc.method, status, headers, body) |
| + } |
| + if a, b := s.Counts(); a != 1 || b != 1 { |
| + t.Fatalf("calls=%d/%d, want 1/1", a, b) |
| + } |
| + status, _, body = s.Request(t, "POST", "/", "once") |
| + if status != 200 || !strings.HasPrefix(body, "holder|") { |
| + t.Fatalf("remembered POST: %d %q", status, body) |
| + } |
| + if a, b := s.Counts(); a != 1 || b != 2 { |
| + t.Fatalf("calls=%d/%d, want 1/2", a, b) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestBackhaulHolderKeepsMemoryOnClientHangup(t *testing.T) { |
| svc, rt, bucket, _ := backhaulHeldService(t, "betty") |
| s := edge.NewBackhaulHolderScene(t, bucket, svc, rt) |
| - status, headers, body := s.Request(t, "GET", "/", "") |
| - if status != 200 || body != "holder|"+rt.Host+"|/" || headers.Get("Retry-After") != "" { |
| - t.Fatalf("GET: %d %v %q; want holder's 200", status, headers, body) |
| - } |
| - if a, b := s.Counts(); a != 1 || b != 1 { |
| - t.Fatalf("calls=%d/%d, want 1/1", a, b) |
| + if status, _, body := s.Request(t, "GET", "/", ""); status != 200 { |
| + t.Fatalf("warm: %d %q", status, body) |
| } |
| - status, _, body = s.Request(t, "POST", "/", "once") |
| - if status != 200 || !strings.HasPrefix(body, "holder|") { |
| - t.Fatalf("remembered POST: %d %q", status, body) |
| + s.CancelHeldRequest(t) |
| + if status, _, body := s.Request(t, "POST", "/", "once"); status != 200 { |
| + t.Fatalf("remembered POST after hangup: %d %q", status, body) |
| } |
| - if a, b := s.Counts(); a != 1 || b != 2 { |
| - t.Fatalf("calls=%d/%d, want 1/2", a, b) |
| + if a, b := s.Counts(); a != 1 || b != 3 { |
| + t.Fatalf("calls=%d/%d, want 1/3; client hangup discarded the holder", a, b) |
| } |
| } |
| @@ -176,7 +209,7 @@ func TestBackhaulHolderStopsAfterSecondAttempt(t *testing.T) { |
| } |
| func TestBackhaulHolderDropsMemory(t *testing.T) { |
| - for _, mode := range []string{"none", "other", "left view", "stale", "expired", "dial failure"} { |
| + for _, mode := range []string{"none", "other", "left view", "stale", "expired", "dial failure", "tls failure"} { |
| t.Run(mode, func(t *testing.T) { |
| svc, rt, bucket, second := backhaulHeldService(t, "betty") |
| s := edge.NewBackhaulHolderScene(t, bucket, svc, rt) |
| @@ -196,10 +229,12 @@ func TestBackhaulHolderDropsMemory(t *testing.T) { |
| s.ExpireMemory() |
| case "dial failure": |
| s.HolderDown() |
| + case "tls failure": |
| + s.HolderTLSFailure() |
| } |
| status, _, body := s.Request(t, "POST", "/", "once") |
| want := 503 |
| - if mode == "dial failure" { |
| + if mode == "dial failure" || mode == "tls failure" { |
| want = 502 |
| } |
| if status != want { |