Skip to content

Commit

Permalink
fix: panic with divide by zero duration math (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielc authored Nov 14, 2023
1 parent 071cd48 commit 55dd5d8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion p2p/src/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,15 @@ impl Stream for Publisher {
let batch_average_seconds = average.as_secs();
let lag_ratio = needed_seconds / deadline_seconds;

if !spare.is_zero() {
if remaining_batches == 0.0 {
// We do not have any more batches, fetch one more to be sure.
// If it comes back empty we will delay until the interval is complete.
self.state = State::StartingFetch;
} else if !spare.is_zero() {
// Be conservative and adjust our delay based on our optimism of
// the estimate.
// If remaining_batches is zero this math panics, so we ensure its
// not zero with the above case.
let delay = spare.div_f64(remaining_batches / OPTIMISM);
debug!(
batch_average_seconds,
Expand Down

0 comments on commit 55dd5d8

Please sign in to comment.