Skip to content

Commit 76c831c

Browse files
committed
graph: Fix an error in KillState::new
On Mac OSX, Instant::now() is the time since the last boot, which might have been less than a day ago, in which case KillState::new would panic. We now use 'now - 60s' as a time in the past for initialization, and if that fails, we'll use just 'now'. There's not much danger in using 'now', it might just lead to spurious logging and a too-soon update of the kill_rate if the node becomes immediately overloaded after starting. Thanks to kevholder for root-causing the issue and demonstrating a fix. Fixes #1805
1 parent 8c54d02 commit 76c831c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

graph/src/data/graphql/effort.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,14 @@ struct KillState {
149149

150150
impl KillState {
151151
fn new() -> Self {
152-
let long_ago = Duration::from_secs(86400);
152+
let long_ago = Duration::from_secs(60);
153+
let now = Instant::now();
154+
let before = now.checked_sub(long_ago).unwrap_or(now);
153155
Self {
154156
kill_rate: 0.0,
155-
last_update: Instant::now() - long_ago,
157+
last_update: before,
156158
overload_start: None,
157-
last_overload_log: Instant::now() - long_ago,
159+
last_overload_log: before,
158160
}
159161
}
160162

0 commit comments

Comments
 (0)