From 5d20c19f36aa8d76242fbea37499f0c70595cc49 Mon Sep 17 00:00:00 2001 From: Jash Ambaliya <87864439+AJ0070@users.noreply.github.com> Date: Tue, 24 Nov 2026 19:16:09 +0530 Subject: [PATCH] fix: event insert retry sleeps between attempts and gives up after 10 refs #7999 (#8000) --- src/zm_event.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/zm_event.cpp b/src/zm_event.cpp index e58dadeaa3..7dd581ca36 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -159,9 +159,17 @@ Event::Event( monitor->Latitude(), monitor->Longitude() ); + // zmDbDoInsert returns 0 on a failure it will not retry itself, so back off and give up after a few tries + int insert_attempts = 0; do { id = zmDbDoInsert(sql); - } while (!id and !zm_terminate); + if (id or zm_terminate) break; + if (++insert_attempts >= 10) { + Error("Unable to insert event after %d attempts", insert_attempts); + break; + } + sleep(1); + } while (true); /* None of these are crucial, and are simple when done as individual transactions */ sql = stringtf("INSERT INTO `Events_Hour` (EventId,MonitorId,StartDateTime,DiskSpace)"