Skip to content

Commit

Permalink
handle channel disconnect (#24036) (#25325)
Browse files Browse the repository at this point in the history
(cherry picked from commit c9a476e)

# Conflicts:
#	rpc/src/rpc_completed_slots_service.rs

Co-authored-by: HaoranYi <[email protected]>
  • Loading branch information
mergify[bot] and HaoranYi authored May 20, 2022
1 parent 9f67d01 commit 86ecb28
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions rpc/src/rpc_completed_slots_service.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use {
crate::rpc_subscriptions::RpcSubscriptions,
crossbeam_channel::RecvTimeoutError,
solana_client::rpc_response::SlotUpdate,
solana_ledger::blockstore::CompletedSlotsReceiver,
solana_sdk::timing::timestamp,
Expand All @@ -25,19 +26,26 @@ impl RpcCompletedSlotsService {
Builder::new()
.name("solana-rpc-completed-slots-service".to_string())
.spawn(move || loop {
// shutdown the service
// received exit signal, shutdown the service
if exit.load(Ordering::Relaxed) {
break;
}

if let Ok(slots) = completed_slots_receiver
match completed_slots_receiver
.recv_timeout(Duration::from_millis(COMPLETE_SLOT_REPORT_SLEEP_MS))
{
for slot in slots {
rpc_subscriptions.notify_slot_update(SlotUpdate::Completed {
slot,
timestamp: timestamp(),
});
Err(RecvTimeoutError::Timeout) => {}
Err(RecvTimeoutError::Disconnected) => {
info!("RpcCompletedSlotService channel disconnected, exiting.");
break;
}
Ok(slots) => {
for slot in slots {
rpc_subscriptions.notify_slot_update(SlotUpdate::Completed {
slot,
timestamp: timestamp(),
});
}
}
}
})
Expand Down

0 comments on commit 86ecb28

Please sign in to comment.