Skip to content

Commit

Permalink
Skip empty results and don't panic if the gRPC client disconnects
Browse files Browse the repository at this point in the history
  • Loading branch information
arya2 committed Feb 15, 2024
1 parent 3bc4258 commit ddc4318
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions zebra-grpc/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -151,7 +155,7 @@ where
tx_id,
}) = results_receiver.recv().await
{
response_sender
let send_result = response_sender
.send(Ok(ScanResponse {
height,
results: [(
Expand All @@ -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;
}
}
});

Expand Down

0 comments on commit ddc4318

Please sign in to comment.