aboutsummaryrefslogtreecommitdiffstats
path: root/netwatch-notify.rsc
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2024-02-26 23:18:02 +0100
committerGravatar Christian Hesse <mail@eworm.de>2024-02-28 23:01:43 +0100
commit93bed1b081bb23624b988627d2db6e71d55e796a (patch)
treeef8e9cfd0d3e0c98c9239fd9cfebe15c125553dc /netwatch-notify.rsc
parentc2f5272f18c2161150481b9569ee17bc2c3d2289 (diff)
netwatch-notify: work around race condition
This used to crash every now and then with: > script;error script error: no such item (4) I guess this is caused by querying the dns cache just exactly when a record expires. The chance is maximized: The script is started by scheduler every minute, and the record's ttl is a multiple of a minute. Let's query records that are not about to expire immediately, and try again.
Diffstat (limited to 'netwatch-notify.rsc')
-rw-r--r--netwatch-notify.rsc20
1 files changed, 12 insertions, 8 deletions
diff --git a/netwatch-notify.rsc b/netwatch-notify.rsc
index 186ac0a..c8de7e1 100644
--- a/netwatch-notify.rsc
+++ b/netwatch-notify.rsc
@@ -80,14 +80,18 @@ $ScriptLock $0;
:do {
:local Resolve [ :resolve ($HostInfo->"resolve") ];
:if ($Resolve != $HostVal->"host" && \
- [ :len [ /ip/dns/cache/find where name=($HostInfo->"resolve") data=[ :tostr ($HostVal->"host") ] ] ] = 0) do={
- $LogPrintExit2 info $0 ("Name '" . $HostInfo->"resolve" . [ $IfThenElse \
- ($HostInfo->"resolve" != $HostInfo->"name") ("' for " . $Type . " '" . \
- $HostInfo->"name") "" ] . "' resolves to different address " . $Resolve . \
- ", updating.") false;
- /tool/netwatch/set host=$Resolve $Host;
- :set ($Metric->"resolve-failcnt") 0;
- :set ($HostVal->"status") "unknown";
+ [ :len [ /ip/dns/cache/find where name=($HostInfo->"resolve") data=[ :tostr ($HostVal->"host") ] ttl>0s ] ] = 0) do={
+ :delay 1500ms;
+ :resolve ($HostInfo->"resolve");
+ :if ([ :len [ /ip/dns/cache/find where name=($HostInfo->"resolve") data=[ :tostr ($HostVal->"host") ] ] ] = 0) do={
+ $LogPrintExit2 info $0 ("Name '" . $HostInfo->"resolve" . [ $IfThenElse \
+ ($HostInfo->"resolve" != $HostInfo->"name") ("' for " . $Type . " '" . \
+ $HostInfo->"name") "" ] . "' resolves to different address " . $Resolve . \
+ ", updating.") false;
+ /tool/netwatch/set host=$Resolve $Host;
+ :set ($Metric->"resolve-failcnt") 0;
+ :set ($HostVal->"status") "unknown";
+ }
}
} on-error={
:set ($Metric->"resolve-failcnt") ($Metric->"resolve-failcnt" + 1);