From ef769bf960c9e24f571b80935e03dcd3d8e61c34 Mon Sep 17 00:00:00 2001 From: Kiall Mac Innes Date: Tue, 12 May 2015 14:59:15 +0100 Subject: [PATCH] Fix check+set race condition in APIv1/Sink Change-Id: I02d22212511246f0c1b8138fa3413770cd5810a1 Closes-Bug: 1454262 --- designate/api/v1/records.py | 8 +++++--- designate/notification_handler/base.py | 15 +++++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/designate/api/v1/records.py b/designate/api/v1/records.py index b7375c11..a6e9b3f1 100644 --- a/designate/api/v1/records.py +++ b/designate/api/v1/records.py @@ -46,9 +46,7 @@ def _find_or_create_recordset(context, domain_id, name, type, ttl): central_api.find_domain(context, criterion=criterion) try: - recordset = _find_recordset(context, domain_id, name, type) - except exceptions.RecordSetNotFound: - # Create an empty recordset + # Attempt to create an empty recordset values = { 'name': name, 'type': type, @@ -58,6 +56,10 @@ def _find_or_create_recordset(context, domain_id, name, type, ttl): recordset = central_api.create_recordset( context, domain_id, objects.RecordSet(**values)) + except exceptions.DuplicateRecordSet: + # Fetch the existing recordset + recordset = _find_recordset(context, domain_id, name, type) + return recordset diff --git a/designate/notification_handler/base.py b/designate/notification_handler/base.py index f43985aa..993141e5 100644 --- a/designate/notification_handler/base.py +++ b/designate/notification_handler/base.py @@ -69,12 +69,7 @@ class NotificationHandler(ExtensionPlugin): name = name.encode('idna') try: - recordset = self.central_api.find_recordset(context, { - 'domain_id': domain_id, - 'name': name, - 'type': type, - }) - except exceptions.RecordSetNotFound: + # Attempt to create an empty recordset values = { 'name': name, 'type': type, @@ -83,6 +78,14 @@ class NotificationHandler(ExtensionPlugin): recordset = self.central_api.create_recordset( context, domain_id, RecordSet(**values)) + except exceptions.DuplicateRecordSet: + # Fetch the existing recordset + recordset = self.central_api.find_recordset(context, { + 'domain_id': domain_id, + 'name': name, + 'type': type, + }) + return recordset