Repository navigation
fix(maintenance): spend the renewal budget on scheduled jobs, not scanned rows - #13572
HarshMN2345 wants to merge 6 commits into
Conversation
…nned rows The renewal scan fetched the first 200 due certificates and then skipped the ones whose rule is missing, lives in another region, or does not apply. Every skipped row still counted against the 200, so on a multi-region deployment the rows another region owns could fill the page and starve the renewals this region should have queued. The same scan also matched a certificate by domain alone, so a rule that had moved on to a new certificate kept renewing the one it left behind. Page through due certificates in sequence order and stop once 200 jobs are actually queued, and only renew the certificate the rule currently references.
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
…ude/maintenance-renewal-budget # Conflicts: # tests/e2e/General/Certificates/Database.php
55392c8 to
ff91d29
Compare
28faa65 to
60e0899
Compare
|
There is no fix in the repo to port. I'll re-run the failed job once the run completes; if it fails the same way twice, the INSTREAM framing gets its own PR rather than widening this one. Generated by Claude Code |
Picks up main via #13572 -> #13571 -> #13570 so CI runs against current main. Conflict in Certificates.php: main added an inline notifyError() call in catch and gave notifyError() a sixth $console parameter. This branch defers that email to the finally block, which sends only once the lease is confirmed still ours, so a stale worker cannot email an admin about a failure that a newer retry has already superseded. Kept the deferred form, dropped the inline call, and carried main's new parameter into the deferred call site -- git would have merged the signature change without touching the call. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MeytoiisEusFMCU44PDYav
bdb52ee to
51abda3
Compare
6647e8b to
01fdcac
Compare
Picks up main via #13572 -> #13571 -> #13570 so CI runs against current main. Conflict in Certificates.php: main added an inline notifyError() call in catch and gave notifyError() a sixth $console parameter. This branch defers that email to the finally block, which sends only once the lease is confirmed still ours, so a stale worker cannot email an admin about a failure that a newer retry has already superseded. Kept the deferred form, dropped the inline call, and carried main's new parameter into the deferred call site -- git would have merged the signature change without touching the call.
…ude/maintenance-renewal-budget
…ude/maintenance-renewal-budget
What does this PR do?
Two bugs in
Maintenance::renewCertificates(), both in how it picks what to renew.1. Skipped rows eat the renewal budget. On
main:find(limit 200)takes the first 200 due certificates, then the loop drops the ones this region doesn't own. Thecertificatestable is shared across regions and has noregioncolumn, so on a multi-region deployment the first 200 due rows can all belong to another region — this region schedules nothing, and its own due renewals wait for the next daily run, where the same thing happens again. Nothing in the logs says so: it prints "Found 200 certificates for renewal, scheduling jobs" and schedules zero.The fix pages through due certificates with
iterate()(limitbecomes the page size, ordered by$sequenceso the cursor is stable) and counts the 200 cap on jobs actually enqueued, breaking once it's reached. The Let's Encrypt headroom is preserved; it's just no longer consumed by rows that never produce an order.2. The wrong certificate gets renewed. The scan matched a rule by domain alone. When a domain is removed and re-added, or the worker creates a fresh certificate document for a rule, the old certificate row stays behind with its
renewDatestill due.mainfinds it, finds the rule by domain, and queues a renewal — for a certificate the rule no longer references. The extra guardrule.certificateId === certificate.$idmakes the rule the authority on which certificate it renews.The
attempts < 5cap, the region check and the Appwrite-owned auto-issue opt-out are unchanged.Test Plan
tests/e2e/General/Certificates/MaintenanceTest.phpruns the realMaintenancetask withtype: 'trigger'against a throwaway PostgreSQL schema and a capturing publisher:other, created first, then 201 due renewals indefault.mainschedules 0 — the other region's rows fill the page. This PR schedules exactly 200, all of themdefault-region renewals. (200 is the Let's Encrypt budget — 300 orders per three hours with 100 held back for new domains — not an internal constant.)renewDate, plus a leftover certificate for the same domain that is due.mainqueues a renewal for the leftover; this PR queues nothing.triggeralso runs the other maintenance steps (project sweep, cache/schedule/CSV cleanup), which is why the fixture'sprojectsstub gainsaccessedAt; those steps only enqueue onto the capturing publisher.Runs in
Tests / E2E / General; skips locally without PostgreSQL.Related PRs and Issues
certificates.updated(nothing onmaindoes; that's fix(certificates): retry failed issuance under a lease and bound the attempts #13573).Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_01MeytoiisEusFMCU44PDYav