ha: keep eligible holders serving through ingress projection failures
Keep app manifest and tombstone failures scoped to their hosts. Cover eligible local holders and unrelated app ingress with regression tests.
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
4 files changed,
+92
−20
internal/edge/haingress.go+3 −0internal/edge/haingress_internal_test.go+49 −0internal/host/haingress_test.go+34 −0internal/provision/haingress.go+6 −20
diff --git a/internal/edge/haingress.go b/internal/edge/haingress.go| index b13813d33..f1bb5831c 100644 |
| --- a/internal/edge/haingress.go |
| +++ b/internal/edge/haingress.go |
| @@ -73,6 +73,9 @@ func (e *Edge) routeHAIngress(w http.ResponseWriter, r *http.Request, host strin |
| } |
| rt, known = e.ingressRoute(primary) |
| } |
| + if local && up.route.HA && e.localPoolEligible(up.route) && (!known || rt.Host == "" || !rt.HA) { |
| + return false |
| + } |
| if !known { |
| if local && !e.localPoolEligible(up.route) { |
| HAUnavailableResponse(w, r) |
diff --git a/internal/edge/haingress_internal_test.go b/internal/edge/haingress_internal_test.go| index 48bce0b76..60c7b7ec8 100644 |
| --- a/internal/edge/haingress_internal_test.go |
| +++ b/internal/edge/haingress_internal_test.go |
| @@ -8,7 +8,9 @@ import ( |
| "strings" |
| "testing" |
| + "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| ) |
| type ingressForwarder struct{ *fwAct } |
| @@ -49,6 +51,53 @@ func TestHAIngressNoHopReplay(t *testing.T) { |
| } |
| func TestHAIngressMetadataCannotGrantLocalAuthority(t *testing.T) { |
| + for _, kind := range []string{"failed refresh", "manifest error", "stale plus valid body"} { |
| + t.Run("eligible holder/"+kind, func(t *testing.T) { |
| + x := newFwScene(t, fwOpts{aAct: &fwAct{}}) |
| + row, err := x.a.reg.Get(fwHost) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + row.Pool = "ha" |
| + if err := x.a.reg.Upsert(*row); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := x.a.edge.Reload(); err != nil { |
| + t.Fatal(err) |
| + } |
| + store := release.NewDirStore(t.TempDir()) |
| + rec := provision.Record{Schema: 1, Host: fwHost, Slug: "ha", Account: row.Account, App: row.App, Channel: "stable", Pool: "ha", HA: true} |
| + if err := provision.PutManifest(t.Context(), store, rec.Account, rec.App, provision.Manifest{Schema: 1, App: rec.App, Domain: "forward.test"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + records := []provision.Record{rec} |
| + switch kind { |
| + case "manifest error": |
| + key := provision.ManifestKey(rec.Account, rec.App) |
| + _, etag, err := store.Get(t.Context(), key) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := store.Put(t.Context(), key, []byte("invalid json"), etag); err != nil { |
| + t.Fatal(err) |
| + } |
| + case "stale plus valid body": |
| + retired := rec |
| + retired.Retired, retired.App = true, "old" |
| + records = append(records, retired) |
| + } |
| + routes, projectionErr := provision.HAIngressRoutesFromRecords(t.Context(), store, records, "") |
| + if kind == "failed refresh" || projectionErr != nil { |
| + routes = map[string]registry.Route{fwHost: {}} |
| + } |
| + x.a.edge.SetHAIngressLookup(func(h string) (registry.Route, bool) { rt, ok := routes[h]; return rt, ok }) |
| + w := httptest.NewRecorder() |
| + x.a.edge.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "https://"+fwHost+"/", nil)) |
| + if w.Code != 200 || x.aApp.n.Load() != 1 || x.bApp.n.Load() != 0 { |
| + t.Fatalf("eligible holder: status=%d local=%d remote=%d body=%s", w.Code, x.aApp.n.Load(), x.bApp.n.Load(), w.Body.String()) |
| + } |
| + }) |
| + } |
| for _, kind := range []string{"absent projection", "failed projection", "held row", "import row", "alias", "alias wrong account", "alias wrong lifetime", "held name", "regional", "foreign regional", "exact before catchall"} { |
| t.Run(kind, func(t *testing.T) { |
| act := &ingressForwarder{&fwAct{target: "betty"}} |
diff --git a/internal/host/haingress_test.go b/internal/host/haingress_test.go| index e364ea045..99d7437ef 100644 |
| --- a/internal/host/haingress_test.go |
| +++ b/internal/host/haingress_test.go |
| @@ -8,6 +8,7 @@ import ( |
| "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| ) |
| func TestHAIngressMetadataCannotGrantLocalAuthority(t *testing.T) { |
| @@ -111,3 +112,36 @@ func TestHAIngressRegionalProjection(t *testing.T) { |
| t.Fatal("deleted regional alias retained") |
| } |
| } |
| + |
| +func TestHAIngressAppReadErrorIsIsolated(t *testing.T) { |
| + for _, kind := range []string{"manifest", "tombstone"} { |
| + t.Run(kind, func(t *testing.T) { |
| + store := release.NewDirStore(t.TempDir()) |
| + good := provision.Record{Schema: 1, Host: "good.example.com", Slug: "good", Account: release.OpsAccount, App: "good", Channel: "stable", Pool: "ha", HA: true} |
| + bad := good |
| + bad.Host, bad.Slug, bad.App = "bad.example.com", "bad", "bad" |
| + for _, rec := range []provision.Record{good, bad} { |
| + if err := provision.PutManifest(t.Context(), store, rec.Account, rec.App, provision.Manifest{Schema: 1, App: rec.App, Domain: "example.com"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + key := provision.ManifestKey(bad.Account, bad.App) |
| + if kind == "tombstone" { |
| + key = release.AppTombstoneKey(bad.Account, bad.App) |
| + } |
| + _, etag, _ := store.Get(t.Context(), key) |
| + if _, err := store.Put(t.Context(), key, []byte("invalid json"), etag); err != nil { |
| + t.Fatal(err) |
| + } |
| + routes, err := provision.HAIngressRoutesFromRecords(t.Context(), store, []provision.Record{bad, good}, "") |
| + var p haIngressProjection |
| + p.publish(routes, err) |
| + if rt, ok := p.lookup(good.Host); !ok || !rt.HA { |
| + t.Fatalf("good app lost ingress: %+v %v err=%v", rt, ok, err) |
| + } |
| + if rt, ok := p.lookup(bad.Host); !ok || rt.HA { |
| + t.Fatalf("bad app gained ingress: %+v %v", rt, ok) |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/provision/haingress.go b/internal/provision/haingress.go| index dc8e10742..065e38f32 100644 |
| --- a/internal/provision/haingress.go |
| +++ b/internal/provision/haingress.go |
| @@ -3,8 +3,6 @@ package provision |
| import ( |
| "context" |
| "errors" |
| - "fmt" |
| - "os" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| @@ -37,12 +35,7 @@ func HAIngressRoutesFromRecords(ctx context.Context, s release.Store, records [] |
| for _, rec := range records { |
| counts[rec.Host]++ |
| } |
| - type appResult struct { |
| - allowed bool |
| - err error |
| - } |
| - apps := map[string]appResult{} |
| - var result error |
| + apps := map[string]bool{} |
| for _, rec := range records { |
| if rec.Region != region && !rec.Retired { |
| continue |
| @@ -56,26 +49,19 @@ func HAIngressRoutesFromRecords(ctx context.Context, s release.Store, records [] |
| continue |
| } |
| key := rec.Account + "/" + rec.App |
| - ar, seen := apps[key] |
| + allowed, seen := apps[key] |
| if !seen { |
| tomb, err := release.ReadAppTombstone(ctx, s, rec.Account, rec.App) |
| - ar.err = err |
| if err == nil && tomb == nil { |
| m, err := GetManifest(ctx, s, rec.Account, rec.App) |
| - ar.allowed = err == nil && m.Schema == 1 && m.App == rec.App |
| - if err != nil && !errors.Is(err, os.ErrNotExist) { |
| - ar.err = err |
| - } |
| + allowed = err == nil && m.Schema == 1 && m.App == rec.App |
| } |
| - apps[key] = ar |
| - } |
| - if ar.err != nil { |
| - result = errors.Join(result, fmt.Errorf("HA ingress %s: %w", key, ar.err)) |
| + apps[key] = allowed |
| } |
| - if !ar.allowed { |
| + if !allowed { |
| continue |
| } |
| out[rec.Host] = registry.Route{Host: rec.Host, Account: rec.Account, App: rec.App, Pool: rec.Pool, Region: rec.Region, HA: true, Incarnation: rec.Incarnation, ServingSeq: rec.MoveSeq} |
| } |
| - return out, result |
| + return out, nil |
| } |