]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Adjust setWeight state retrieve mechanism
authorn0tlu5 <darfisultoni@gmail.com>
Thu, 23 May 2024 01:40:14 +0000 (08:40 +0700)
committern0tlu5 <darfisultoni@gmail.com>
Thu, 23 May 2024 01:40:14 +0000 (08:40 +0700)
pdns/lua-record.cc

index a5970a7d0f337180b70739bcaa98805f796da1e0..2259ca561b12220f391c23b7201655510c1c2a59 100644 (file)
@@ -233,9 +233,17 @@ private:
   }
   
   void setWeight(const CheckDesc& cd, string content){
-    ReadLock lock{&d_lock};
-    auto& state = d_statuses[cd];
-    state->weight = stoi(content);
+    auto statuses = d_statuses.write_lock();
+    auto& state = (*statuses)[cd];
+    try {
+      state->weight = stoi(content);
+    } catch (const PDNSException& e) {
+      // set weight to 0
+      state->weight = 0;
+    }
+    if (state->first) {
+      state->first = false;
+    }
   }
 
   void setDown(const ComboAddress& rem, const std::string& url=std::string(), const opts_t& opts = opts_t())