From: n0tlu5 Date: Thu, 23 May 2024 01:40:14 +0000 (+0700) Subject: Adjust setWeight state retrieve mechanism X-Git-Tag: dnsdist-2.0.0-alpha1~178^2~15 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fc8d9909b3a918b72f5310c9a523474ac2c24ad7;p=thirdparty%2Fpdns.git Adjust setWeight state retrieve mechanism --- 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())