From 1f119c6807d261be6540b77acf1524f6449d6305 Mon Sep 17 00:00:00 2001 From: aeon Date: Thu, 11 Jan 2024 12:59:02 +0800 Subject: [PATCH] Fix potential panic when Stats drops --- examples/examples/z_sub_thr.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/examples/z_sub_thr.rs b/examples/examples/z_sub_thr.rs index 671e50f88b..afdd07ed23 100644 --- a/examples/examples/z_sub_thr.rs +++ b/examples/examples/z_sub_thr.rs @@ -58,7 +58,10 @@ impl Stats { } impl Drop for Stats { fn drop(&mut self) { - let elapsed = self.global_start.unwrap().elapsed().as_secs_f64(); + let Some(global_start) = self.global_start else { + return; + }; + let elapsed = global_start.elapsed().as_secs_f64(); let total = self.round_size * self.finished_rounds + self.round_count; let throughtput = total as f64 / elapsed; println!("Received {total} messages over {elapsed:.2}s: {throughtput}msg/s");