From 909316bd5366e67daaf76ae63aac96a29ed02f5c Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 4 May 2020 14:27:40 -0700 Subject: [PATCH] Avoid panic caused by converting non-positive / non-normal floating points values to duration (#9867) (#9872) (cherry picked from commit 3aedb81d4899f75e87f5b338bfbfea8d0c624a6f) Co-authored-by: Kristofer Peterson --- cli/src/cluster_query.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cli/src/cluster_query.rs b/cli/src/cluster_query.rs index 3a9e3096d3..cc2e9c179f 100644 --- a/cli/src/cluster_query.rs +++ b/cli/src/cluster_query.rs @@ -486,14 +486,13 @@ pub fn process_catchup( let slot_distance = rpc_slot as i64 - node_slot as i64; let slots_per_second = (previous_slot_distance - slot_distance) as f64 / f64::from(sleep_interval); - let time_remaining = if slots_per_second <= 0.0 { + let time_remaining = (slot_distance as f64 / slots_per_second).round(); + let time_remaining = if !time_remaining.is_normal() || time_remaining <= 0.0 { "".to_string() } else { format!( ". Time remaining: {}", - humantime::format_duration(Duration::from_secs_f64( - (slot_distance as f64 / slots_per_second).round() - )) + humantime::format_duration(Duration::from_secs_f64(time_remaining)) ) };