Skip to content

Commit

Permalink
Handle errors when sending a snapshot package during shutdown (solana…
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored May 30, 2023
1 parent b799b86 commit a4ff9be
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions core/src/accounts_hash_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ impl AccountsHashVerifier {
&mut hashes,
&snapshot_config,
accounts_hash_fault_injector,
&exit,
));

// Done processing the current snapshot, so the current snapshot dir
Expand Down Expand Up @@ -246,6 +247,7 @@ impl AccountsHashVerifier {
hashes: &mut Vec<(Slot, Hash)>,
snapshot_config: &SnapshotConfig,
accounts_hash_fault_injector: Option<AccountsHashFaultInjector>,
exit: &AtomicBool,
) {
let accounts_hash =
Self::calculate_and_verify_accounts_hash(&accounts_package, snapshot_config);
Expand All @@ -265,6 +267,7 @@ impl AccountsHashVerifier {
snapshot_package_sender,
snapshot_config,
accounts_hash,
exit,
);
}

Expand Down Expand Up @@ -547,6 +550,7 @@ impl AccountsHashVerifier {
snapshot_package_sender: Option<&Sender<SnapshotPackage>>,
snapshot_config: &SnapshotConfig,
accounts_hash: AccountsHashEnum,
exit: &AtomicBool,
) {
if !snapshot_config.should_generate_snapshots()
|| !matches!(
Expand All @@ -561,9 +565,15 @@ impl AccountsHashVerifier {
};

let snapshot_package = SnapshotPackage::new(accounts_package, accounts_hash);
snapshot_package_sender
.send(snapshot_package)
.expect("send snapshot package");
let send_result = snapshot_package_sender.send(snapshot_package);
if let Err(err) = send_result {
// Sending the snapshot package should never fail *unless* we're shutting down.
let snapshot_package = &err.0;
assert!(
exit.load(Ordering::Relaxed),
"Failed to send snapshot package: {err}, {snapshot_package:?}"
);
}
}

pub fn join(self) -> thread::Result<()> {
Expand Down Expand Up @@ -597,6 +607,7 @@ mod tests {
solana_logger::setup();
let cluster_info = new_test_cluster_info();
let cluster_info = Arc::new(cluster_info);
let exit = AtomicBool::new(false);

let mut hashes = vec![];
let full_snapshot_archive_interval_slots = 100;
Expand All @@ -621,6 +632,7 @@ mod tests {
&mut hashes,
&snapshot_config,
None,
&exit,
);

// sleep for 1ms to create a newer timestamp for gossip entry
Expand Down

0 comments on commit a4ff9be

Please sign in to comment.