From fc8d9909b3a918b72f5310c9a523474ac2c24ad7 Mon Sep 17 00:00:00 2001 From: n0tlu5 Date: Thu, 23 May 2024 08:40:14 +0700 Subject: [PATCH] Adjust setWeight state retrieve mechanism --- pdns/lua-record.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pdns/lua-record.cc b/pdns/lua-record.cc index a5970a7d0f..2259ca561b 100644 --- a/pdns/lua-record.cc +++ b/pdns/lua-record.cc @@ -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()) -- 2.47.2