edge: hold a new name's first order until the other edges can answer for it (#443)
Human
Prompt
Paul asked (2026-10-28) to do the nearest-region follow-ups. Yours is amadan discussion #443: on DEV, a newly created hostname served from Dublin (ie) fails its first certificate request, and stays unreachable for about 8 minutes. That's longer than carlos deploy's 2-minute watch. Find the root cause before proposing a fix.
From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.
Summary
The issuer ordered a certificate about a second after minting a route, before the deployment's other edges had polled the name into their home maps. Let's Encrypt validates from several places and geo DNS sends some of them to another edge, which refused the challenge for a name it did not know yet, so the order failed and the host stayed dark until a handshake happened to reach the issuer again. issuerHostPolicy now holds a name the issuer first saw less than one home map poll plus 15 s ago (45 s), only when another box publishes an edges file; the cert warm treats the hold as not-yet (no 1 h backoff, no failure record, order budget handed back) and comes back when it ends. Census: internal/edge envelope re-pinned.
Agent notes
Evidence on #443: dennis logged 'no token cert' for the new ie host from LE's Stockholm and Singapore validators 5 s after the mint, while its home map learned the host 13 s after. Reproduced on v0.28.29 with shop-cert-1028.
7 files changed,
+507
−3
docs/superpowers/notes/census-proposal-cert-warm-propagation-443.md+11 −0internal/edge/certsettle.go+185 −0internal/edge/certsettle_test.go+252 −0internal/edge/certsync.go+13 −1internal/edge/certwarm.go+42 −2internal/provision/testdata/plan14-root-reads-cert-warm-propagation-443.tsv+3 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0
CI cancelled — superseded by a newer push — run details
diff --git a/docs/superpowers/notes/census-proposal-cert-warm-propagation-443.md b/docs/superpowers/notes/census-proposal-cert-warm-propagation-443.md| new file mode 100644 |
| index 000000000..4287a4954 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-cert-warm-propagation-443.md |
| @@ -0,0 +1,11 @@ |
| +# Census approval: cert-warm-propagation-443 |
| + |
| +Ruling `census-ruling-cert-warm-propagation-443`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +Envelopes re-pinned: `internal/edge`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Escalate if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. An escalation goes to the census owner as a decision. |
| + |
| +Seal: `4337475617b84cadf26e62a31387b7de1b6e9174bf5e6fa4d191f2d2a024e930` → `4337475617b84cadf26e62a31387b7de1b6e9174bf5e6fa4d191f2d2a024e930`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-cert-warm-propagation-443.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/edge/certsettle.go b/internal/edge/certsettle.go| new file mode 100644 |
| index 000000000..086363209 |
| --- /dev/null |
| +++ b/internal/edge/certsettle.go |
| @@ -0,0 +1,185 @@ |
| +// Name settling (#443): the issuer does not order a certificate for a name |
| +// until every other edge in the deployment has had the chance to learn it. |
| +// |
| +// Why. The CA validates one order from several places at once, and DNS for a |
| +// platform name answers with whichever edge is nearest each of them (latency |
| +// or geo routing), so some of those validations arrive at an edge that is not |
| +// the issuer. That edge answers the challenge from the bucket (certsync.go's |
| +// alpnTokenCert and challengeResponse), but only for names it already knows, |
| +// which is the bound that stops a stranger's SNI from turning into bucket |
| +// reads. It learns another box's names from its home map, polled every |
| +// homeMapInterval. The issuer, meanwhile, orders the moment it sees a name: |
| +// the cert warm's wake (#386) runs about a second after a route is minted, |
| +// and a client's first handshake does the same. So on the box that homes a |
| +// new name, the order went out seconds before the other edges could know the |
| +// name, their validations failed, and the order failed with them ("no viable |
| +// challenge type found"). autocert then refuses the name for a minute, the |
| +// warm backs off for an hour, and steering keeps most handshakes on edges |
| +// that never order, so a new host stayed dark for minutes (dev's ie hosts, |
| +// 2026-10-26 to 10-28: five of five). |
| +// |
| +// The rule: a name the issuer first saw less than nameSettleWindow ago is |
| +// not ordered yet. The window is one home map poll plus a margin, which is |
| +// long enough for every other edge to have polled once since the name was |
| +// published. It applies only where there IS another edge (a home map that |
| +// lists another box): a single box has nobody to wait for. |
| +// |
| +// It holds NEW orders only in practice. HostPolicy runs before autocert's |
| +// cache read, so a held name is not served from autocert's cache either; on |
| +// the issuer the mirror and the local cache sit behind autocert |
| +// (certMirror.wrapGetCertificate), so a name that already has a certificate |
| +// (one that moved here) keeps being served through the window. |
| +package edge |
| + |
| +import ( |
| + "errors" |
| + "sync" |
| + "time" |
| +) |
| + |
| +// nameSettleMargin is added to the poll interval to cover the home box's |
| +// edges file write (internal/host's 2 s registry watch plus the put) and the |
| +// other box's own poll, which lists and reads every edges file. |
| +const nameSettleMargin = 15 * time.Second |
| + |
| +// nameSettleWindow is how long the issuer waits after first seeing a name |
| +// before it orders for it. Derived from homeMapInterval so the two cannot |
| +// drift apart. |
| +func nameSettleWindow() time.Duration { return homeMapInterval + nameSettleMargin } |
| + |
| +// errNameSettling is the hold's sentinel. Its text is generic for |
| +// errNotIssuer's reason: autocert's HTTPHandler writes a HostPolicy error to |
| +// the wire verbatim. |
| +var errNameSettling = errors.New("acme: not available yet") |
| + |
| +// settlingError is the hold as HostPolicy returns it, carrying how long is |
| +// left so the cert warm can come back on time rather than on a guess. |
| +type settlingError struct { |
| + left time.Duration |
| +} |
| + |
| +func (e *settlingError) Error() string { return errNameSettling.Error() } |
| + |
| +func (e *settlingError) Is(target error) bool { return target == errNameSettling } |
| + |
| +// settleLeft extracts the time left from a hold, and false for any other |
| +// error. |
| +func settleLeft(err error) (time.Duration, bool) { |
| + var se *settlingError |
| + if errors.As(err, &se) { |
| + return se.left, true |
| + } |
| + return 0, false |
| +} |
| + |
| +// nameAges records when this box first saw each name it can order for: its |
| +// own routes and every name another box publishes. The names present when it |
| +// is built are dated zero (always settled), so a restart holds nothing; a |
| +// name that appears later is dated when it was first noticed. |
| +// |
| +// It rebuilds only when the route map or the home map snapshot changes, and |
| +// both are replaced whole rather than edited (Edge.Reload, homeMap.refreshHosts), |
| +// so a pointer comparison is enough and the handshake path pays a map lookup. |
| +// A rebuild drops names that have gone, so the map stays the size of the |
| +// deployment, and a name that comes back is new again. |
| +type nameAges struct { |
| + now func() time.Time |
| + |
| + mu sync.Mutex |
| + own *map[string]upstream |
| + homes *homeSnapshot |
| + first map[string]time.Time |
| +} |
| + |
| +func newNameAges(e *Edge, now func() time.Time) *nameAges { |
| + a := &nameAges{now: now} |
| + a.mu.Lock() |
| + a.rebuild(e, true) |
| + a.mu.Unlock() |
| + return a |
| +} |
| + |
| +// wait is how long until host may be ordered: zero when it may be now. |
| +// A name the tracker has never seen is not held. That covers names that are |
| +// in neither map (the tunnel host) and keeps an unexpected shape on today's |
| +// behaviour rather than holding it forever. |
| +func (a *nameAges) wait(e *Edge, host string) time.Duration { |
| + if !e.homes.Load().hasPeer() { |
| + return 0 |
| + } |
| + a.mu.Lock() |
| + defer a.mu.Unlock() |
| + a.rebuild(e, false) |
| + first, ok := a.first[host] |
| + if !ok || first.IsZero() { |
| + return 0 |
| + } |
| + return max(first.Add(nameSettleWindow()).Sub(a.now()), 0) |
| +} |
| + |
| +// rebuild re-reads both name sets when either has changed. Called with a.mu |
| +// held. |
| +func (a *nameAges) rebuild(e *Edge, baseline bool) { |
| + own := e.upstreams.Load() |
| + var snap *homeSnapshot |
| + if hm := e.homes.Load(); hm != nil { |
| + snap = hm.snapshot() |
| + } |
| + if !baseline && own == a.own && snap == a.homes { |
| + return |
| + } |
| + // The first snapshot that comes from a successful read is a baseline of |
| + // its own: when the boot refresh failed, the map starts empty, and the |
| + // poll that finally lands is not news about every name in it. |
| + homesBaseline := baseline || a.homes == nil || !a.homes.read |
| + a.own, a.homes = own, snap |
| + now := a.now() |
| + next := make(map[string]time.Time, len(a.first)) |
| + note := func(h string, old bool) { |
| + if _, dup := next[h]; dup { |
| + return |
| + } |
| + switch t, ok := a.first[h]; { |
| + case ok: |
| + next[h] = t |
| + case old: |
| + next[h] = time.Time{} |
| + default: |
| + next[h] = now |
| + } |
| + } |
| + if own != nil { |
| + for h := range *own { |
| + note(h, baseline) |
| + } |
| + } |
| + if snap != nil { |
| + for h := range snap.hosts { |
| + note(h, homesBaseline) |
| + } |
| + } |
| + a.first = next |
| +} |
| + |
| +// hasPeer reports whether another box publishes an edges file, which is what |
| +// makes this a deployment with more than one edge. With no box label every |
| +// file counts, which only ever errs towards holding. |
| +func (m *homeMap) hasPeer() bool { |
| + if m == nil { |
| + return false |
| + } |
| + for _, f := range m.snapshot().files { |
| + if f.Box != "" && f.Box != m.self { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| + |
| +// holdIfSettling is HostPolicy's last step on the issuer. |
| +func (a *nameAges) holdIfSettling(e *Edge, host string) error { |
| + if left := a.wait(e, host); left > 0 { |
| + return &settlingError{left: left} |
| + } |
| + return nil |
| +} |
diff --git a/internal/edge/certsettle_test.go b/internal/edge/certsettle_test.go| new file mode 100644 |
| index 000000000..089db0cb5 |
| --- /dev/null |
| +++ b/internal/edge/certsettle_test.go |
| @@ -0,0 +1,252 @@ |
| +package edge |
| + |
| +import ( |
| + "context" |
| + "crypto/tls" |
| + "errors" |
| + "sync" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/certwarm" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// #443. The CA validates a name from several places at once, and DNS for a |
| +// platform name answers with whichever edge is nearest each of them, so some |
| +// validations arrive at an edge that is not the issuer. That edge can answer |
| +// only for names it knows, and it learns another box's names from its home map |
| +// poll. A name the issuer has just minted is not in that map yet, so an order |
| +// placed straight away fails before the other edges have had a chance to |
| +// learn the name. The fix holds a NEW order until one poll interval (and a |
| +// margin) has passed since the issuer first saw the name. |
| + |
| +// clockAt is a settable test clock. |
| +type clockAt struct { |
| + mu sync.Mutex |
| + t time.Time |
| +} |
| + |
| +func (c *clockAt) now() time.Time { |
| + c.mu.Lock() |
| + defer c.mu.Unlock() |
| + return c.t |
| +} |
| + |
| +func (c *clockAt) advance(d time.Duration) { |
| + c.mu.Lock() |
| + c.t = c.t.Add(d) |
| + c.mu.Unlock() |
| +} |
| + |
| +// settleEdge is the issuer of a two-box deployment: it serves own from its |
| +// registry and holds the issuer lease, and box "betty" publishes homed. |
| +func settleEdge(t *testing.T, own []string, homed ...string) (*Edge, *homeMap) { |
| + t.Helper() |
| + e := testIssuerEdge(own...) |
| + e.issuer = func() (context.Context, bool) { return context.Background(), true } |
| + m := newHomeMap(release.NewDirStore(t.TempDir()), "annie") |
| + homedOn(t, m, "betty", "2.2.2.2", homed...) |
| + e.homes.Store(m) |
| + return e, m |
| +} |
| + |
| +// mint adds host to the edge's registry the way a reload does: a new map |
| +// behind a new pointer. |
| +func mint(e *Edge, host string) { |
| + next := map[string]upstream{} |
| + for h, u := range e.current() { |
| + next[h] = u |
| + } |
| + next[host] = upstream{} |
| + e.upstreams.Store(&next) |
| +} |
| + |
| +func TestHostPolicyHoldsANameItHasJustMinted(t *testing.T) { |
| + clk := &clockAt{t: time.Unix(1_800_000_000, 0)} |
| + e, _ := settleEdge(t, []string{"old.test"}, "remote-old.test") |
| + pol := e.issuerHostPolicyAt(clk.now) |
| + |
| + for _, h := range []string{"old.test", "remote-old.test"} { |
| + if err := pol(context.Background(), h); err != nil { |
| + t.Fatalf("%s was there when the policy was built: want no hold, got %v", h, err) |
| + } |
| + } |
| + |
| + mint(e, "new.test") |
| + err := pol(context.Background(), "new.test") |
| + if !errors.Is(err, errNameSettling) { |
| + t.Fatalf("a name minted a moment ago = %v, want errNameSettling", err) |
| + } |
| + var se *settlingError |
| + if !errors.As(err, &se) || se.left != nameSettleWindow() { |
| + t.Fatalf("settling error = %#v, want the whole window (%s) left", err, nameSettleWindow()) |
| + } |
| + |
| + clk.advance(nameSettleWindow() - time.Second) |
| + if err := pol(context.Background(), "new.test"); !errors.Is(err, errNameSettling) { |
| + t.Fatalf("one second before the window ends = %v, want still settling", err) |
| + } |
| + clk.advance(time.Second) |
| + if err := pol(context.Background(), "new.test"); err != nil { |
| + t.Fatalf("after the window: want the order allowed, got %v", err) |
| + } |
| +} |
| + |
| +// The window covers the box that is slowest to learn the name, and that box |
| +// polls on its own phase, so it must be at least one home map poll. |
| +func TestNameSettleWindowCoversAHomeMapPoll(t *testing.T) { |
| + if nameSettleWindow() <= homeMapInterval { |
| + t.Fatalf("window %s must be longer than the home map poll %s", nameSettleWindow(), homeMapInterval) |
| + } |
| +} |
| + |
| +// A name homed on ANOTHER box reaches the issuer through its own home map |
| +// poll, and a third box may still be a poll behind it, so it is held too. |
| +func TestHostPolicyHoldsANameAnotherBoxHasJustPublished(t *testing.T) { |
| + clk := &clockAt{t: time.Unix(1_800_000_000, 0)} |
| + e, m := settleEdge(t, []string{"old.test"}, "remote-old.test") |
| + pol := e.issuerHostPolicyAt(clk.now) |
| + |
| + homedOn(t, m, "betty", "2.2.2.2", "remote-old.test", "remote-new.test") |
| + if err := pol(context.Background(), "remote-new.test"); !errors.Is(err, errNameSettling) { |
| + t.Fatalf("a name another box just published = %v, want errNameSettling", err) |
| + } |
| + if err := pol(context.Background(), "remote-old.test"); err != nil { |
| + t.Fatalf("an old remote name must not be held by a new map: %v", err) |
| + } |
| + clk.advance(nameSettleWindow()) |
| + if err := pol(context.Background(), "remote-new.test"); err != nil { |
| + t.Fatalf("after the window: want the order allowed, got %v", err) |
| + } |
| +} |
| + |
| +// One box, nobody else to wait for: a new name is ordered at once, as before. |
| +func TestHostPolicyDoesNotHoldWithoutAnotherEdge(t *testing.T) { |
| + clk := &clockAt{t: time.Unix(1_800_000_000, 0)} |
| + e := testIssuerEdge("old.test") |
| + e.issuer = func() (context.Context, bool) { return context.Background(), true } |
| + m := newHomeMap(release.NewDirStore(t.TempDir()), "annie") |
| + homedOn(t, m, "annie", "1.1.1.1", "old.test") // only this box's own file |
| + e.homes.Store(m) |
| + pol := e.issuerHostPolicyAt(clk.now) |
| + |
| + mint(e, "new.test") |
| + if err := pol(context.Background(), "new.test"); err != nil { |
| + t.Fatalf("single-edge deployment: want no hold, got %v", err) |
| + } |
| + |
| + // No home map at all (no deployment store): today's behaviour, too. |
| + e2 := testIssuerEdge("old.test") |
| + pol2 := e2.issuerHostPolicyAt(clk.now) |
| + mint(e2, "new.test") |
| + if err := pol2(context.Background(), "new.test"); err != nil { |
| + t.Fatalf("no home map: want no hold, got %v", err) |
| + } |
| +} |
| + |
| +// The hold is the issuer's alone and comes after the two existing refusals: |
| +// a non-issuer still says errNotIssuer and a stranger is still unknown. |
| +func TestHostPolicySettleComesAfterTheExistingRefusals(t *testing.T) { |
| + clk := &clockAt{t: time.Unix(1_800_000_000, 0)} |
| + e, _ := settleEdge(t, []string{"old.test"}, "remote-old.test") |
| + pol := e.issuerHostPolicyAt(clk.now) |
| + mint(e, "new.test") |
| + |
| + if err := pol(context.Background(), "stranger.test"); err == nil || errors.Is(err, errNameSettling) { |
| + t.Fatalf("unknown host = %v, want the registry refusal", err) |
| + } |
| + e.issuer = func() (context.Context, bool) { return nil, false } |
| + if err := pol(context.Background(), "new.test"); !errors.Is(err, errNotIssuer) { |
| + t.Fatalf("non-issuer = %v, want errNotIssuer", err) |
| + } |
| +} |
| + |
| +// A name that leaves and comes back (a move away and back) is new again. |
| +func TestHostPolicyHoldsANameThatReturns(t *testing.T) { |
| + clk := &clockAt{t: time.Unix(1_800_000_000, 0)} |
| + e, _ := settleEdge(t, []string{"old.test", "mover.test"}, "remote-old.test") |
| + pol := e.issuerHostPolicyAt(clk.now) |
| + if err := pol(context.Background(), "mover.test"); err != nil { |
| + t.Fatalf("baseline name: %v", err) |
| + } |
| + gone := map[string]upstream{"old.test": {}} |
| + e.upstreams.Store(&gone) |
| + if err := pol(context.Background(), "old.test"); err != nil { // rebuild without mover |
| + t.Fatalf("old.test: %v", err) |
| + } |
| + clk.advance(time.Hour) |
| + mint(e, "mover.test") |
| + if err := pol(context.Background(), "mover.test"); !errors.Is(err, errNameSettling) { |
| + t.Fatalf("a name that came back = %v, want errNameSettling", err) |
| + } |
| +} |
| + |
| +// The warm meets the hold as "not yet", not as a failed order: no hourly |
| +// backoff, no failure record, no order budget spent, and a pass soon after |
| +// the window ends. |
| +func TestWarmWaitsOutASettlingNameWithoutFailing(t *testing.T) { |
| + store := release.NewDirStore(t.TempDir()) |
| + settled := false |
| + calls := 0 |
| + w := newCertWarm( |
| + func() []string { return []string{"new.test"} }, |
| + func(*tls.ClientHelloInfo) (*tls.Certificate, error) { |
| + calls++ |
| + if !settled { |
| + return nil, &settlingError{left: 20 * time.Second} |
| + } |
| + return &tls.Certificate{}, nil |
| + }, |
| + func(string) bool { return true }, |
| + nil, |
| + store, |
| + ) |
| + delay := w.pass() |
| + if delay > 20*time.Second+warmSettleSlack || delay < 20*time.Second { |
| + t.Fatalf("pass returned %s, want the time left in the window (20s, plus at most %s)", delay, warmSettleSlack) |
| + } |
| + w.mu.Lock() |
| + until, backing := w.nextAttempt["new.test"] |
| + orders := len(w.recentOrders) |
| + w.mu.Unlock() |
| + if backing && time.Until(until) > time.Minute { |
| + t.Fatalf("a settling name was put on a %s backoff", time.Until(until).Round(time.Second)) |
| + } |
| + if orders != 0 { |
| + t.Fatalf("a held order spent %d of the order budget", orders) |
| + } |
| + if keys, _ := store.List(context.Background(), certwarm.Prefix); len(keys) != 0 { |
| + t.Fatalf("a held order wrote a failure record: %v", keys) |
| + } |
| + |
| + settled = true |
| + w.mu.Lock() |
| + delete(w.nextAttempt, "new.test") // the window has passed |
| + w.mu.Unlock() |
| + w.pass() |
| + w.mu.Lock() |
| + warmed := w.warmed["new.test"] |
| + w.mu.Unlock() |
| + if !warmed || calls != 2 { |
| + t.Fatalf("after the window: warmed=%v calls=%d, want the order placed", warmed, calls) |
| + } |
| +} |
| + |
| +// A wake arriving while the name settles must not trigger a pass that would |
| +// only meet the hold again; the warm already has its own pass coming. |
| +func TestWarmDoesNotTreatASettlingNameAsNew(t *testing.T) { |
| + w := newCertWarm( |
| + func() []string { return []string{"new.test"} }, |
| + func(*tls.ClientHelloInfo) (*tls.Certificate, error) { |
| + return nil, &settlingError{left: 30 * time.Second} |
| + }, |
| + func(string) bool { return true }, |
| + nil, |
| + nil, |
| + ) |
| + w.pass() |
| + if w.hasNewHost() { |
| + t.Fatal("a settling name read as new: every reload in the fleet would rerun the pass") |
| + } |
| +} |
diff --git a/internal/edge/certsync.go b/internal/edge/certsync.go| index ba54d8564..bf9045dfc 100644 |
| --- a/internal/edge/certsync.go |
| +++ b/internal/edge/certsync.go |
| @@ -190,7 +190,19 @@ func (e *Edge) armCertIssuance(inner autocert.Cache) autocert.Cache { |
| // days early), so there is deliberately NO fencing token here and no |
| // readiness predicate on the election: a fence would trade a rare duplicate |
| // order for a deployment that can stop issuing altogether. |
| +// |
| +// Last, on the issuer only: a name it first saw less than one home map poll |
| +// ago is held (certsettle.go, #443), because the other edges the CA will |
| +// also validate through cannot answer for it yet. |
| func (e *Edge) issuerHostPolicy() autocert.HostPolicy { |
| + return e.issuerHostPolicyAt(time.Now) |
| +} |
| + |
| +// issuerHostPolicyAt is issuerHostPolicy on a given clock. The names the |
| +// edge serves when it is called are dated as already settled, so it must be |
| +// built after the registry and the home map's first refresh, as Run does. |
| +func (e *Edge) issuerHostPolicyAt(now func() time.Time) autocert.HostPolicy { |
| + ages := newNameAges(e, now) |
| return func(_ context.Context, host string) error { |
| if !e.deploymentHost(host) { |
| return fmt.Errorf("acme: host %q not in registry", host) |
| @@ -198,7 +210,7 @@ func (e *Edge) issuerHostPolicy() autocert.HostPolicy { |
| if _, ok := e.issuerGate(); !ok { |
| return errNotIssuer |
| } |
| - return nil |
| + return ages.holdIfSettling(e, host) |
| } |
| } |
diff --git a/internal/edge/certwarm.go b/internal/edge/certwarm.go| index eda46391a..966b6b11f 100644 |
| --- a/internal/edge/certwarm.go |
| +++ b/internal/edge/certwarm.go |
| @@ -94,6 +94,10 @@ const ( |
| // enough that one pass over many new hosts reads the bucket once, not once |
| // per host, while the bucket is down. |
| warmEdgeSetEmptyTTL = 30 * time.Second |
| + // warmSettleSlack is how long after a held name's window ends the warm |
| + // comes back for it (certsettle.go): enough that the pass lands after the |
| + // window, not on its edge. |
| + warmSettleSlack = 2 * time.Second |
| ) |
| // certWarm proactively orders and renews per-host certificates. |
| @@ -456,6 +460,9 @@ func (c *certWarm) pass() time.Duration { |
| inSet[h] = true |
| } |
| orders, capped := 0, false |
| + // settleWait is the shortest hold met this pass (certsettle.go); zero |
| + // when none was. |
| + var settleWait time.Duration |
| budget := c.orderBudget(c.now()) |
| for _, h := range hosts { |
| now := c.now() |
| @@ -499,6 +506,22 @@ func (c *certWarm) pass() time.Duration { |
| orders++ |
| } |
| if err := c.warmOne(h); err != nil { |
| + if left, ok := settleLeft(err); ok { |
| + // Held, not failed (certsettle.go, #443): the other edges |
| + // cannot answer for this name yet. No backoff, no record, and |
| + // the order budget stamped above is handed back. |
| + if !seen { |
| + c.mu.Lock() |
| + c.recentOrders = c.recentOrders[:len(c.recentOrders)-1] |
| + c.mu.Unlock() |
| + orders-- |
| + } |
| + c.settling(h, left) |
| + if settleWait == 0 || left < settleWait { |
| + settleWait = left |
| + } |
| + continue |
| + } |
| c.fail(gctx, h, err, records[h]) |
| continue |
| } |
| @@ -535,10 +558,27 @@ func (c *certWarm) pass() time.Duration { |
| // met a host it had to skip: a host attached a moment later must not be |
| // left for the hourly pass because its wake arrived while the budget was |
| // empty. |
| + delay := warmInterval |
| if capped || (orders > 0 && orders >= budget) { |
| - return warmCappedDelay |
| + delay = warmCappedDelay |
| + } |
| + // Back just after the earliest held name settles, so a new host gets its |
| + // certificate within about a minute of being minted. |
| + if settleWait > 0 { |
| + delay = min(delay, settleWait+warmSettleSlack) |
| } |
| - return warmInterval |
| + return delay |
| +} |
| + |
| +// settling puts a held name back for when its hold ends. nextAttempt is the |
| +// floor pass() and hasNewHost already honour, so the name is neither retried |
| +// early nor counted as new by a wake in the meantime. |
| +func (c *certWarm) settling(host string, left time.Duration) { |
| + until := c.now().Add(left) |
| + c.mu.Lock() |
| + c.nextAttempt[host] = until |
| + c.mu.Unlock() |
| + log.Printf("edge: cert warm for %s waits %s for the other edges to learn the name", host, left.Round(time.Second)) |
| } |
| // warmOne asks autocert for host's certificate, which mints it when absent |
diff --git a/internal/provision/testdata/plan14-root-reads-cert-warm-propagation-443.tsv b/internal/provision/testdata/plan14-root-reads-cert-warm-propagation-443.tsv| new file mode 100644 |
| index 000000000..c7c9cea01 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-cert-warm-propagation-443.tsv |
| @@ -0,0 +1,3 @@ |
| +# Census overlay cert-warm-propagation-443, written by census-propose (#369). census-ruling-cert-warm-propagation-443, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-cert-warm-propagation-443.md. |
| +# 0 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@coverage internal/edge 387587cecc89fa53c8aa21177ee397b11551010ee69ea5ef2775cf9156b9395f |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 96a507acc..35636da6e 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -18,3 +18,4 @@ plan14-root-reads-plans-6b-checkout-flow.tsv f5afdacd495705841fcc8441eaefe0efb9d |
| plan14-root-reads-nearest-region-followups.tsv f5afdacd495705841fcc8441eaefe0efb9db7056de281bb06d1714960a5575b7 |
| plan14-root-reads-region-ha-p1b1.tsv 185170fe393cb565d18a3359dee5ace12676b3e1adecb8b638199d25ceeb779f |
| plan14-root-reads-rootfs-apps-3.tsv 4337475617b84cadf26e62a31387b7de1b6e9174bf5e6fa4d191f2d2a024e930 |
| +plan14-root-reads-cert-warm-propagation-443.tsv 4337475617b84cadf26e62a31387b7de1b6e9174bf5e6fa4d191f2d2a024e930 |