[pbs-devel] [PATCH 2/2] rrd: clamp future last_update time on load

Thomas Lamprecht t.lamprecht at proxmox.com
Thu Nov 14 14:29:50 CET 2024


We had already cases reported about systems where the BIOS had a time
rather far in the future and thus anything that requires some time
ordering might fail if it was initialised before an NTP system managed
to sync the clock again.

RRD updates are one such things, so as stop-gap just clam the
last_update time on load.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---

it might be nicer to clamp when saving the file, as that also has a
higher chance to a NTP client having run and thus avoiding an error in
the other direction, i.e., when the system is booted with time in the
past. So feell free to take this over and rework for that case, just
sending it out as I had a prototype around for some recent debug session
on my machine.

 proxmox-rrd/src/rrd.rs | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/proxmox-rrd/src/rrd.rs b/proxmox-rrd/src/rrd.rs
index 4bf4f01b..73a0ebd4 100644
--- a/proxmox-rrd/src/rrd.rs
+++ b/proxmox-rrd/src/rrd.rs
@@ -378,6 +378,11 @@ impl Database {
 
         if rrd.source.last_update < 0.0 {
             bail!("rrd file has negative last_update time");
+        } else if rrd.source.last_update > proxmox_time::epoch_f64() {
+            let mut rrd = rrd;
+            log::error!("rrd file has last_update time from the future, clamping to now!");
+            rrd.source.last_update = proxmox_time::epoch_f64();
+            return Ok(rrd);
         }
 
         Ok(rrd)
-- 
2.39.5





More information about the pbs-devel mailing list