handle channel disconnect (#24036)

This commit is contained in:
HaoranYi 2022-04-01 13:47:06 -05:00 committed by GitHub
parent df4d92f9cf
commit c9a476e24d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 7 deletions

View File

@ -1,5 +1,6 @@
use { use {
crate::rpc_subscriptions::RpcSubscriptions, crate::rpc_subscriptions::RpcSubscriptions,
crossbeam_channel::RecvTimeoutError,
solana_client::rpc_response::SlotUpdate, solana_client::rpc_response::SlotUpdate,
solana_ledger::blockstore::CompletedSlotsReceiver, solana_ledger::blockstore::CompletedSlotsReceiver,
solana_sdk::timing::timestamp, solana_sdk::timing::timestamp,
@ -25,14 +26,20 @@ impl RpcCompletedSlotsService {
Builder::new() Builder::new()
.name("solana-rpc-completed-slots-service".to_string()) .name("solana-rpc-completed-slots-service".to_string())
.spawn(move || loop { .spawn(move || loop {
// shutdown the service // received exit signal, shutdown the service
if exit.load(Ordering::Relaxed) { if exit.load(Ordering::Relaxed) {
break; break;
} }
if let Ok(slots) = completed_slots_receiver match completed_slots_receiver
.recv_timeout(Duration::from_millis(COMPLETE_SLOT_REPORT_SLEEP_MS)) .recv_timeout(Duration::from_millis(COMPLETE_SLOT_REPORT_SLEEP_MS))
{ {
Err(RecvTimeoutError::Timeout) => {}
Err(RecvTimeoutError::Disconnected) => {
info!("RpcCompletedSlotService channel disconnected, exiting.");
break;
}
Ok(slots) => {
for slot in slots { for slot in slots {
rpc_subscriptions.notify_slot_update(SlotUpdate::Completed { rpc_subscriptions.notify_slot_update(SlotUpdate::Completed {
slot, slot,
@ -40,6 +47,7 @@ impl RpcCompletedSlotsService {
}); });
} }
} }
}
}) })
.unwrap() .unwrap()
} }