From 1ef966f339c7081063ca998ea8fe0beb123b43e2 Mon Sep 17 00:00:00 2001 From: Amolith Date: Mon, 13 Nov 2023 17:05:06 -0500 Subject: [PATCH] Eliminate a registration race condition Check whether we've actually deleted anything before proceeding with registration; if we have not deleted anything, it means another customer has registered that number before this one could. Signed-off-by: Amolith --- lib/tel_selections.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/tel_selections.rb b/lib/tel_selections.rb index 246598c1c3816148281e541abb7f4cde1bce1d72..8c0df302157a6fca1a4ca4a64eb2cecee6026333 100644 --- a/lib/tel_selections.rb +++ b/lib/tel_selections.rb @@ -317,6 +317,7 @@ class TelSelections tel, customer.customer_id, @bandwidth_account_id ) db.exec_defer("DELETE FROM tel_inventory WHERE tel = $1", [tel]) + .then { |r| raise unless r.cmd_tuples.positive? } end end end