fix(dns): idempotent DDNS trigger attach — stop config applies deadlocking live DDNS #88
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/ddns-trigger-idempotent-no-view-lock"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes the recurring DDNS timeouts +
octet-dns-3/postgresdeadlocks.Root cause (confirmed from dns-3's deadlock log): PowerDNS's
recordsis a VIEW — RFC 2136 DDNS writes flow through an INSTEAD OF trigger intodns_records.ensureDdnsOutboxOnClientranDROP TRIGGER+CREATE TRIGGERon that view on every config apply, and CREATE/DROP TRIGGER takes an AccessExclusiveLock on the view. Because the apply takes that lock after itsdns_recordsupserts, it forms a deadlock cycle with a concurrent PowerDNS DDNS insert (which holds an AccessShareLock on the view + a conflicting row). Postgres kills one; when PowerDNS is the victim, its update fails → Kea logs SERVFAIL (RCODE 2) ortimed out.Deadlock detail (dns-3): proc A
insert into records (…)for a PTR; proc B waiting forAccessExclusiveLock on relation 458803(therecordsview). dns-3 was hit hardest: first in the Kea D2 list (all DDNS load) + constant zone churn (frequent applies).Fix: the trigger references
ddns_outbox_instead_of_fnby name and that function isCREATE OR REPLACE'd every apply, so an existing trigger is always current — it only vanishes whencreate_pdns_schema_for_view'sCREATE OR REPLACE VIEWdrops it (a genuine regeneration). So (re)create it only when absent. A steady-state apply now takes no lock on therecordsview, eliminating the deadlock window; a regeneration still re-attaches it in the same transaction.Relation to earlier PRs: #74 added a deadlock retry on the sync side, but PowerDNS (a separate binary) can't retry, so it kept losing. #87 (local-first D2 order) reduced dns-3's share of the load. This removes the collision itself.
Tests: mock-client unit tests (skip-when-present / create-when-absent / always-probes); existing ddns-outbox + local-dns-sync deadlock-retry tests still green; agent typecheck clean.
Takes effect on the next member (dns) image deploy.
🤖 Generated with Claude Code