Repository navigation
Conversation
Write the rollover header directly via FileHandler.emit() rather than re-entering the rotating handler. A wall clock jump during rollover can otherwise trigger a nested rollover and duplicate the header. Signed-off-by: Sergei Rozhkov <zmod@zmod.link>
|
The change looks fine to me. But how would this happen in practice? The clock would need to jump past the next midnight in the short window between computing rolloverAt and writing the header. Did you see this on a real system? -Maksim |
|
On printers without an RTC, the system clock starts at Unix time 0. Klipper may already be running when time synchronization occurs, causing the clock to jump forward by decades. If synchronization happens during log rotation, the clock can easily jump past the next rollover boundary before the header is written. This is a realistic scenario on embedded systems. |
|
Yes, we encountered infinite log rotation on real printers running Z-Mod. These embedded systems can boot with the system clock at Unix time 0 and start Klipper before NTP synchronization, resulting in large clock jumps. You can see this startup sequence here: We resolved our log rotation issues by switching from time-based to size-based rotation: I no longer have the original diagnostic logs to confirm that the exact timing scenario described in this PR caused the observed issue. However, large clock jumps while Klipper is running are normal on these systems. |
Writing the rollover header through
self.emit()re-enters the rotating handler and performs another rollover check.If the system clock advances past the next rollover boundary during rotation, this can trigger a nested rollover, create an empty rotated log file, and duplicate the rollover header.
Write the header directly through
logging.FileHandler.emit()to avoid re-entering the rotation logic.Verified on Python 3.13 with a simulated clock jump during rotation. Before the fix, two rollovers occurred and the header was duplicated. After the fix, only one rollover occurred and the header was written once.
The existing protection introduced in #7387 is preserved.