mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-21 10:30:41 +08:00
node: Protect against non-monotonic clocks
Many (most?) system clocks are not monotonic, and even though we're getting a `LocalTime`, which *is* monotonic when using `now()`, it is constructed from a `SystemTime` which isn't.
This commit is contained in:
@@ -676,7 +676,17 @@ where
|
||||
"Tick +{}",
|
||||
now - self.started_at.expect("Service::tick: service must be initialized")
|
||||
);
|
||||
self.clock = now;
|
||||
if now >= self.clock {
|
||||
self.clock = now;
|
||||
} else {
|
||||
// Nb. In tests, we often move the clock forwards in time to test different behaviors,
|
||||
// so this warning isn't applicable there.
|
||||
#[cfg(not(test))]
|
||||
warn!(
|
||||
target: "service",
|
||||
"System clock is not monotonic: {now} is not greater or equal to {}", self.clock
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn wake(&mut self) {
|
||||
|
||||
Reference in New Issue
Block a user