Skip to content

Commit

Permalink
graph: Fix an error in KillState::new
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lutter committed Jul 24, 2020
1 parent 8c54d02 commit 76c831c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions graph/src/data/graphql/effort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,14 @@ struct KillState {

impl KillState {
fn new() -> Self {
let long_ago = Duration::from_secs(86400);
let long_ago = Duration::from_secs(60);
let now = Instant::now();
let before = now.checked_sub(long_ago).unwrap_or(now);
Self {
kill_rate: 0.0,
last_update: Instant::now() - long_ago,
last_update: before,
overload_start: None,
last_overload_log: Instant::now() - long_ago,
last_overload_log: before,
}
}

Expand Down

0 comments on commit 76c831c

Please sign in to comment.