fix: terminate on closed persistence task (#9910)

This commit is contained in:
Matthias Seitz
2024-07-30 18:52:52 +02:00
committed by GitHub
parent 27e609df1e
commit bc48459dae

View File

@ -47,6 +47,7 @@ use std::{
use tokio::sync::{
mpsc::{UnboundedReceiver, UnboundedSender},
oneshot,
oneshot::error::TryRecvError,
};
use tracing::*;
@ -522,15 +523,23 @@ where
.rx
.as_mut()
.expect("if a persistence task is in progress Receiver must be Some");
// Check if persistence has completed
if let Ok(last_persisted_block_hash) = rx.try_recv() {
if let Some(block) = self.state.tree_state.block_by_hash(last_persisted_block_hash)
{
self.persistence_state.finish(last_persisted_block_hash, block.number);
self.on_new_persisted_block();
} else {
error!("could not find persisted block with hash {last_persisted_block_hash} in memory");
match rx.try_recv() {
Ok(last_persisted_block_hash) => {
if let Some(block) =
self.state.tree_state.block_by_hash(last_persisted_block_hash)
{
self.persistence_state.finish(last_persisted_block_hash, block.number);
self.on_new_persisted_block();
} else {
error!("could not find persisted block with hash {last_persisted_block_hash} in memory");
}
}
Err(TryRecvError::Closed) => {
panic!("persistence task has been terminated");
}
_ => {}
}
}
}