{"record":{"id":"52860d970fa09d9e","repo":"TechnitiumSoftware/DnsServer","slug":"cannot-update-record-the-record-does-not-exists-t-52860d","errorCode":null,"errorMessage":"Cannot update record: the record does not exists to be updated.","messagePattern":"Cannot update record: the record does not exists to be updated\\.","errorType":"exception","errorClass":"DnsServerException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/Zones/PrimaryZone.cs","lineNumber":2765,"sourceCode":"                case DnsResourceRecordType.DNSKEY:\n                case DnsResourceRecordType.RRSIG:\n                case DnsResourceRecordType.NSEC:\n                case DnsResourceRecordType.NSEC3PARAM:\n                case DnsResourceRecordType.NSEC3:\n                    throw new InvalidOperationException(\"Cannot update DNSSEC records.\");\n\n                default:\n                    if (oldRecord.Type != newRecord.Type)\n                        throw new InvalidOperationException(\"Old and new record types do not match.\");\n\n                    if ((_dnssecStatus != AuthZoneDnssecStatus.Unsigned) && newRecord.GetAuthGenericRecordInfo().Disabled)\n                        throw new DnsServerException(\"Cannot update record: disabling records in a signed zones is not supported.\");\n\n                    if (newRecord.OriginalTtlValue > GetZoneSoaExpire())\n                        throw new DnsServerException(\"Cannot update record: TTL cannot be greater than SOA EXPIRE.\");\n\n                    if (!TryDeleteRecord(oldRecord.Type, oldRecord.RDATA, out DnsResourceRecord deletedRecord))\n                        throw new DnsServerException(\"Cannot update record: the record does not exists to be updated.\");\n\n                    AddRecord(newRecord, out IReadOnlyList<DnsResourceRecord> addedRecords, out IReadOnlyList<DnsResourceRecord> deletedRecords);\n\n                    List<DnsResourceRecord> allDeletedRecords = new List<DnsResourceRecord>(deletedRecords.Count + 1);\n                    allDeletedRecords.Add(deletedRecord);\n                    allDeletedRecords.AddRange(deletedRecords);\n\n                    CommitAndIncrementSerial(allDeletedRecords, addedRecords);\n\n                    if (_dnssecStatus != AuthZoneDnssecStatus.Unsigned)\n                        UpdateDnssecRecordsFor(this, oldRecord.Type);\n\n                    TriggerNotify();\n                    break;\n            }\n        }\n\n        #endregion","sourceCodeStart":2747,"sourceCodeEnd":2783,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/Zones/PrimaryZone.cs#L2747-L2783","documentation":"Thrown by PrimaryZone.UpdateRecord (default case) when TryDeleteRecord(oldRecord.Type, oldRecord.RDATA, ...) returns false, meaning the exact old record is not present. UpdateRecord performs a delete-then-add; if the old record is absent it cannot proceed. DnsServerException marks it as a state/data error.","triggerScenarios":"Calling zone.UpdateRecord(oldRecord, newRecord) when oldRecord (by type+rdata) no longer exists in the zone, e.g. it was already modified, deleted, or never added.","commonSituations":"Concurrent updates where another writer changed the record first; stale oldRecord captured from a cached zone snapshot; retrying an update after a prior success.","solutions":["Re-fetch the current record from the zone before calling UpdateRecord.","Check existence first and Add instead of Update if the record is new.","Handle concurrent edits with optimistic retry against fresh data."],"exampleFix":"// before\nzone.UpdateRecord(staleOldRecord, newRecord);\n\n// after\nvar current = zone.GetRecords(type)?.FirstOrDefault(r => r.RDATA.Equals(staleOldRecord.RDATA));\nif (current is null)\n    zone.AddRecord(newRecord);\nelse\n    zone.UpdateRecord(current, newRecord);","handlingStrategy":"validation","validationCode":"var current = zone.GetRecords(oldRecord.Type)?\n    .FirstOrDefault(r => r.RDATA.Equals(oldRecord.RDATA));\nif (current is null)\n    zone.AddRecord(newRecord);\nelse\n    zone.UpdateRecord(current, newRecord);","typeGuard":"static bool RecordExists(PrimaryZone zone, DnsResourceRecord r) =>\n    zone.GetRecords(r.Type)?.Any(x => x.RDATA.Equals(r.RDATA)) == true;","tryCatchPattern":"try { zone.UpdateRecord(oldRecord, newRecord); }\ncatch (DnsServerException ex) when (ex.Message.Contains(\"does not exists\"))\n{ /* re-fetch and retry, or Add */ }","preventionTips":["Re-read the live record before updating under concurrency.","Use optimistic retry against a freshly fetched oldRecord.","Distinguish 'create' from 'update' at the call site."],"tags":["dns","primary-zone","validation","update","concurrency","not-found"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}