From a41f213668308b0510a74948694535a51605180d Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 28 Sep 2022 10:55:24 +0200 Subject: [statistics] Prevent out-of-order event handling --- modules-available/statistics/api.inc.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php index 88b27d86..6f4917b0 100644 --- a/modules-available/statistics/api.inc.php +++ b/modules-available/statistics/api.inc.php @@ -220,6 +220,10 @@ if ($type[0] === '~') { 'oldlastseen' => $old['lastseen'], 'oldstate' => $old['state'], ); + if ($NOW - $old['lastseen'] < 10 && ($old['state'] === 'OFFLINE' || $old['state'] === 'STANDBY')) { + // Avoid racing calls to ~runstate updates while/after we send a ~poweroff or ~suspend + die("OK.\n"); + } if ($old['state'] === 'OFFLINE') { // This should never happen -- we expect a poweron event before runstate, which would set the state to IDLE // So it might be that the poweron event got lost, or that a couple of runstate events got lost, which -- cgit v1.2.3-55-g7522