From ddc43186a5bf8a2a395721801c9c9a8b5a079ab6 Mon Sep 17 00:00:00 2001 From: Arya Date: Wed, 14 Feb 2024 17:25:02 -0500 Subject: [PATCH] Skip empty results and don't panic if the gRPC client disconnects --- zebra-grpc/src/server.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/zebra-grpc/src/server.rs b/zebra-grpc/src/server.rs index 0e297ebbe96..26a40f7bad5 100644 --- a/zebra-grpc/src/server.rs +++ b/zebra-grpc/src/server.rs @@ -123,6 +123,10 @@ where ); for (height, results_for_key) in results_by_height { + if results_for_key.is_empty() { + continue; + } + let results_for_height = initial_results.entry(height).or_default(); results_for_height.entry(key.clone()).or_default().extend( results_for_key @@ -151,7 +155,7 @@ where tx_id, }) = results_receiver.recv().await { - response_sender + let send_result = response_sender .send(Ok(ScanResponse { height, results: [( @@ -163,8 +167,12 @@ where .into_iter() .collect(), })) - .await - .expect("sender should not be dropped"); + .await; + + // Finish task if the client has disconnected + if send_result.is_err() { + break; + } } });