]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3798] drop packet on db race
authorRazvan Becheriu <razvan@isc.org>
Fri, 14 Mar 2025 08:20:06 +0000 (10:20 +0200)
committerRazvan Becheriu <razvan@isc.org>
Fri, 14 Mar 2025 15:23:17 +0000 (15:23 +0000)
ChangeLog
src/lib/dhcpsrv/alloc_engine.cc
src/lib/dhcpsrv/memfile_lease_mgr.cc
src/lib/dhcpsrv/mysql_lease_mgr.cc
src/lib/dhcpsrv/pgsql_lease_mgr.cc

index f749df6d368c03c7ca42e606a49070751ab335f5..27d38147caffe4745196b77d1d7c59b719d809e2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2260.  [bug]           razvan
+       Fixed a bug which was causing the allocation engine to reject the
+       lease if a data race caused by a different server updating the
+       shared database entries was detected. The entire packet is now
+       dropped in this particular case. This applies to both kea-dhp4
+       and kea-dhcp6 servers.
+       (Gitlab #3798, #3648)
+
 2259.  [bug]           marcin
        Prevent the clients from declining expired or released leases.
        Only a valid lease assigned to the declining client can now
index 6019012b1f911532735faaeed9ee60c27ec70930..c7c84b1edb93e0943fc7db2fde1b94c537a3c2a2 100644 (file)
@@ -15,6 +15,7 @@
 #include <dhcpsrv/alloc_engine.h>
 #include <dhcpsrv/alloc_engine_log.h>
 #include <dhcpsrv/cfgmgr.h>
+#include <dhcpsrv/dhcpsrv_exceptions.h>
 #include <dhcpsrv/dhcpsrv_log.h>
 #include <dhcpsrv/host_mgr.h>
 #include <dhcpsrv/host.h>
@@ -628,6 +629,9 @@ AllocEngine::allocateLeases6(ClientContext6& ctx) {
             return (leases);
         }
 
+    } catch (const NoSuchLease& e) {
+        isc_throw(NoSuchLease, "detected data race in AllocEngine::allocateLeases6: " << e.what());
+
     } catch (const isc::Exception& e) {
 
         // Some other error, return an empty lease.
@@ -2172,6 +2176,9 @@ AllocEngine::renewLeases6(ClientContext6& ctx) {
 
         return (leases);
 
+    } catch (const NoSuchLease& e) {
+        isc_throw(NoSuchLease, "detected data race in AllocEngine::renewLeases6: " << e.what());
+
     } catch (const isc::Exception& e) {
 
         // Some other error, return an empty lease.
@@ -3704,6 +3711,9 @@ AllocEngine::allocateLease4(ClientContext4& ctx) {
             ctx.new_lease_ = requestLease4(ctx);
         }
 
+    } catch (const NoSuchLease& e) {
+        isc_throw(NoSuchLease, "detected data race in AllocEngine::allocateLease4: " << e.what());
+
     } catch (const isc::Exception& e) {
         // Some other error, return an empty lease.
         LOG_ERROR(alloc_engine_logger, ALLOC_ENGINE_V4_ALLOC_ERROR)
index db4f5d577c789fdcfb6b9a53622cc614f6654bcf..350a0397ad73e47e60d25d9c94cd793409731aaf 100644 (file)
@@ -1831,8 +1831,9 @@ Memfile_LeaseMgr::updateLease4Internal(const Lease4Ptr& lease) {
         ((*lease_it)->valid_lft_ != lease->current_valid_lft_))) {
         // For test purpose only: check that the lease has not changed in
         // the database.
-        isc_throw(NoSuchLease, "failed to update the lease with address "
-                  << lease->addr_ << " - lease has changed in database");
+        isc_throw(NoSuchLease, "unable to update lease for address " <<
+                  lease->addr_.toText() << " either because the lease does not exist, "
+                      "it has been deleted or it has changed in the database.");
     }
 
     // Try to write a lease to disk first. If this fails, the lease will
@@ -1894,8 +1895,9 @@ Memfile_LeaseMgr::updateLease6Internal(const Lease6Ptr& lease) {
         ((*lease_it)->valid_lft_ != lease->current_valid_lft_))) {
         // For test purpose only: check that the lease has not changed in
         // the database.
-        isc_throw(NoSuchLease, "failed to update the lease with address "
-                  << lease->addr_ << " - lease has changed in database");
+        isc_throw(NoSuchLease, "unable to update lease for address " <<
+                  lease->addr_.toText() << " either because the lease does not exist, "
+                      "it has been deleted or it has changed in the database.");
     }
 
     // Try to write a lease to disk first. If this fails, the lease will
index 0f4fc005e6bb0e83348c89e30c87c90775502cde..3bb5d1d83c1df192686f635906143d812a92913c 100644 (file)
@@ -3265,7 +3265,8 @@ MySqlLeaseMgr::updateLeaseCommon(MySqlLeaseContextPtr& ctx,
     // If no rows affected, lease doesn't exist.
     if (affected_rows == 0) {
         isc_throw(NoSuchLease, "unable to update lease for address " <<
-                  lease->addr_.toText() << " as it does not exist");
+                  lease->addr_.toText() << " either because the lease does not exist, "
+                      "it has been deleted or it has changed in the database.");
     }
 
     // Should not happen - primary key constraint should only have selected
index 7bb7bf30e4ae56e94ecc78a95851081f365f63b4..e88c1d25cf39026b24a3325831ff9349ed824541 100644 (file)
@@ -2499,7 +2499,8 @@ PgSqlLeaseMgr::updateLeaseCommon(PgSqlLeaseContextPtr& ctx,
     // If no rows affected, lease doesn't exist.
     if (affected_rows == 0) {
         isc_throw(NoSuchLease, "unable to update lease for address " <<
-                  lease->addr_.toText() << " as it does not exist");
+                  lease->addr_.toText() << " either because the lease does not exist, "
+                      "it has been deleted or it has changed in the database.");
     }
 
     // Should not happen - primary key constraint should only have selected