Repository navigation
fix(deletes): keep a recreated domain's certificate when its old rule is deleted - #13570
Conversation
… is deleted Rule deletion is queued, so the deletes worker can run after the same domain has been added again under a new rule. It then tore down the provider certificate and routing that the new rule had just set up, and dropped the certificate record the new rule may reference, leaving the recreated domain without TLS until someone retried it by hand. Only clean up the provider and dispatch RuleDeleted when no rule holds the domain any more, and only delete the certificate record when no rule references it. Pass the rule's domain type to the provider so cleanup reaches the provider that issued the certificate.
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
API rules persist `deploymentResourceType` as '' (the attribute default), and `Document::getAttribute()` only substitutes its default for an absent attribute, so the fallback to `type` never fired for them once the rule had been through the database. Build the test collections from the canonical definitions so the schema the worker is tested against cannot drift from production, and seed the API case with the persisted default so the fallback is exercised on real data.
ad1305f to
b667f6c
Compare
|
No fix to port. I'll re-run the failed job once the run completes; if it fails the same way twice it gets looked at on its own, not here. Generated by Claude Code |
The worker test drives the queue and the database directly and never builds an HTTP client, so the response-format override read by the e2e Scope is meaningless to it. Dropping it also keeps the workflow_dispatch input out of this step's shell command.
main dropped one of the getDB callables from Deletes::action(), leaving it at 18 parameters. DeletesTest still passed 19, so every argument from the sixth onward landed one position early — a closure arrived where Device $deviceForFiles was expected. PHPStan caught it in CI as "invoked with 19 parameters, 18 required"; it was invisible locally because this container cannot install composer.lock (the project now needs PHP 8.5+ and the sandbox has 8.4), so the vendored dependencies still carry the old signature. The split PRs #13570-#13573 drive this worker through the registered worker and the real DI container instead of a hand-written argument list, so none of them had to change. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MeytoiisEusFMCU44PDYav
Refreshes the base so CI runs against current main (PHP 8.5, the reworked Deletes worker, the executions store). No conflicts: main did not touch deleteRule(), and this branch's test drives the registered worker through DI rather than calling action() positionally, so main's signature change is absorbed.
Picks up main via #13570 so CI runs against current main. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MeytoiisEusFMCU44PDYav
Picks up main via #13571 -> #13570 so CI runs against current main. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MeytoiisEusFMCU44PDYav
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
75b6731 to
193ce56
Compare
Picks up main via #13570 so CI runs against current main.
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.
The Proxy adapter matrix is where this PR runs the certificate deletion worker tests, and it is currently failing on MariaDB and MongoDB. The failure cannot be read back: the job log is around twenty thousand lines, the API serves only the last five thousand, and an unbounded dump of every container's output fills that window with runner metrics. Same bound already applied to this step further up the stack, ported down so every pull request below it inherits a readable log.
The certificateId lookup could never match a rule. Every rule creation site persists an empty certificateId, the only writer of a real id is the certificates worker updating the single rule it processed, and _key_domain is unique, so a certificate document is 1:1 with a rule. The rule's own row is always gone before the worker runs. That left an unindexed scan of rules on every deletion, guarding a delete it always permitted. Restore the unconditional cleanup: a replacement rule allocates its own certificate document, so keeping the old one orphans a renewal that reschedules forever. Derive the domain type the way the issuing sites do. deploymentResourceType defaults to '' and is always persisted, so the default argument never fires and an API rule issues under ''. Falling back on empty instead sent the delete to 'api', a different bucket than the one the certificate was issued under.
…r test The suite needed four classes to run. A Database subclass switched over _APP_DB_ADAPTER by hand, which the worker's own message resources already do from the production factory, and that switch was the only thing the dedicated CI step existed for: phpunit already collects tests/e2e/General recursively, so e2e_general ran the file anyway. A Listener subclass observed a RuleDeleted dispatch that has no subscriber and sits in the same branch as the provider call, so the recorded provider calls carry the claim. The Provider fake becomes an anonymous class in the method that needs it. Two cases go with the helpers: both fabricated a pair of rules sharing one certificateId, which a unique domain index makes unreachable. testDeleteProjectRules duplicated testCreateRuleDeletesOrphanedRule, which already covers the same throwaway project, conflict, project delete and recreate. Neither Proxy test can observe this fix: verifyRule() rejects a test domain, so those rules never get a certificate at all. Restore the unbounded failure log dump, which was a separate concern and applied to one of the three dumps.
Resolving dbForPlatform from the container pulled in the pool-backed cache, and popping a pooled connection needs a Swoole coroutine the PHPUnit process is not in, so every case errored with "Failed to acquire lock". Build the database from the registry connection with no cache instead, which is what keeps this test out of the pools entirely. Restore the queue boundary with it. Calling the action directly skipped message encoding and job routing, so a break in either would not have failed the test. The publisher, broker and worker come back; the provider fake stays an anonymous class and the listener stays gone.
There was a problem hiding this comment.
I would remove this test, its not something we can E2E properly, mocking everything around is not really good test either.
I would trust manual QA much more here - reproduce problem on prod, then deploy this to stage, and see same flow work on stage
The race needs a real certificate for a real domain, which the e2e stack cannot issue, so the harness had to stand in for the queue, the database and the provider around the one call under test. Verifying this on stage against a reproduction from prod is the more honest check.
main dropped the worker-level deletion test from #13570 before merging, and with it the Certificates/ fixtures. This branch still needs two of them: Database.php builds the throwaway schema every certificate test runs against, and Provider.php is the recording certificate provider WorkerTest drives. Both are kept; DeletesTest.php and Deletion.php belonged to the deletion test and go with it.
What does this PR do?
Rule deletion is queued, so the deletes worker can run after the same domain has been added again under a new rule — delete a rule, add the domain back, and the old delete job lands second. On
main,Deletes::deleteRule()then tears down the provider certificate and routing that the new rule just set up.The recreated domain is left with no TLS until someone retries it by hand.
The fix guards the provider teardown on the domain still being free:
RuleDeletedonly when no rule holds the domain any more.rules._key_domainis a unique index, so a singlefindOneondomainis exact. If a rule exists, the domain is live and the provider must be left alone.main. A replacement rule always allocates its own certificate document, so keeping the old one orphans a record that reschedules renewals forever.deleteCertificate()also now receives the rule's domain type, derived the same way the issuing sites derive it (getAttribute('deploymentResourceType', getAttribute('type'))).deploymentResourceTypedefaults to''and is always persisted, so an API rule issues under''— the delete has to agree, or a multi-provider deployment routes the teardown to a different bucket than the one that issued.Note: this argument is inert in server-ce —
LetsEncrypt::deleteCertificate()ignores it and this is the only call site — so it only matters downstream.Test Plan
Verified manually, not by an automated test. The race needs a real certificate for a real domain, and the e2e stack cannot issue one:
verifyRule()rejects a test domain, so a*.custom.localhostrule never reaches certificate issuance,certificateIdstays'', andLetsEncrypt::deleteCertificate()unlinks a directory that was never created. A worker-level test was tried and dropped — standing in for the queue, the database and the provider around the single call under test does not buy confidence here. Per review, the check is to reproduce on prod, deploy to stage, and confirm the same flow works there.tests/e2e/Services/Proxy/ProxyBase.phpgainstestDeleteAPIRule, covering API rule deletion, the missing-rule errors, and domain reuse through the public API. To be explicit: it does not gate this fix and passes unchanged onmain. It is general Proxy-surface coverage that did not exist before.Pint, PHPStan (level 4) and a Rector dry run are clean on the changed files.
Related PRs and Issues
Checklist