log-forward: try to mitigate a race condition

The old code looped over all new messages, then updated the variable
to the newest message - at that time! Messages in between were lost.
This commit is contained in:
Christian Hesse 2026-01-13 23:01:23 +01:00
parent 6fd28bf8f7
commit cc56680206

View file

@ -62,7 +62,11 @@
:set LogForwardInclude [ $EitherOr $LogForwardInclude [] ]; :set LogForwardInclude [ $EitherOr $LogForwardInclude [] ];
:set LogForwardIncludeMessage [ $EitherOr $LogForwardIncludeMessage [] ]; :set LogForwardIncludeMessage [ $EitherOr $LogForwardIncludeMessage [] ];
:local LogAll [ /log/find ];
:local MaxId ($LogAll->([ :len $LogAll ] - 1));
:local MaxNum [ $HexToNum $MaxId ];
:local LogForwardFilterLogForwardingCached [ $EitherOr [ $LogForwardFilterLogForwarding ] ("\$^") ]; :local LogForwardFilterLogForwardingCached [ $EitherOr [ $LogForwardFilterLogForwarding ] ("\$^") ];
:foreach Message in=[ /log/find where (!(message="") and \ :foreach Message in=[ /log/find where (!(message="") and \
!(message~$LogForwardFilterLogForwardingCached) and \ !(message~$LogForwardFilterLogForwardingCached) and \
!(topics~$LogForwardFilter) and !(message~$LogForwardFilterMessage)) or \ !(topics~$LogForwardFilter) and !(message~$LogForwardFilterMessage)) or \
@ -70,7 +74,8 @@
:set MessageVal [ /log/get $Message ]; :set MessageVal [ /log/get $Message ];
:local Bullet "information"; :local Bullet "information";
:if ($Last < [ $HexToNum ($MessageVal->".id") ]) do={ :local Current [ $HexToNum ($MessageVal->".id") ];
:if ($Last < $Current && $Current <= $MaxNum) do={
:local DupCount ($MessageDups->($MessageVal->"message")); :local DupCount ($MessageDups->($MessageVal->"message"));
:if ($MessageVal->"topics" ~ "(warning)") do={ :if ($MessageVal->"topics" ~ "(warning)") do={
:set Warning true; :set Warning true;
@ -106,8 +111,7 @@
:set LogForwardRateLimit [ $MAX 0 ($LogForwardRateLimit - 1) ]; :set LogForwardRateLimit [ $MAX 0 ($LogForwardRateLimit - 1) ];
} }
:local LogAll [ /log/find ]; :set LogForwardLast $MaxId;
:set LogForwardLast ($LogAll->([ :len $LogAll ] - 1) );
} do={ } do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err; :global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
} }