Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error logs on translator tasks errors #79

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 31 additions & 26 deletions client/src/main_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,40 @@ pub async fn run_client(args: CliArgs, config: AppConfig) -> Result<Shutdown, Er
"Telos translator client launching, awaiting result...",
);

let mut translator_handle = Box::pin(tokio::spawn(translator.launch(Some(block_sender))));

tokio::select! {
result = client_handle => {
if let Err(error) = result.map_err(From::from).and_then(|inner| inner) {
warn!("Consensus client run failed! Error: {error:?}");

if let Err(error) = translator_shutdown.shutdown().await {
warn!("Cannot send shutdown signal! Error: {error:?}");
}

if let Err(error) = translator_handle.as_mut().await {
warn!("Cannot stop translator! Error: {error:?}");
}

warn!("Retrying...");
return Err(error);
}
},
result = translator_handle.as_mut() => {
if let Err(error) = result.map_err(From::from).and_then(|inner| inner) {
warn!("Translator run failed! Error: {error:?}");

warn!("Retrying...");
return Err(TranslatorShutdown(error.to_string()));
}
let translator_handle = tokio::spawn(translator.launch(Some(block_sender)));

let client_error = client_handle
.await
.map_err(From::from)
.and_then(|inner| inner)
.err();

if let Some(error) = client_error.as_ref() {
warn!("Consensus client run failed! Error: {error:#}");
}

if !translator_shutdown.is_finished() {
if let Err(error) = translator_shutdown.shutdown().await {
warn!("Cannot send shutdown signal! Error: {error:#}");
}
}

let translator_error = translator_handle
.await
.map_err(From::from)
.and_then(|inner| inner)
.map_err(|error| TranslatorShutdown(error.to_string()))
.err();

if let Some(error) = translator_error.as_ref() {
warn!("Translator run failed! Error: {error:#}");
}

if let Some(error) = client_error.or(translator_error) {
warn!("Retrying...");
return Err(error);
}

info!("Reached stop block/signal, consensus client run finished!");
Ok(client_shutdown)
}
Expand Down
19 changes: 13 additions & 6 deletions translator/src/translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ impl Shutdown {
pub async fn shutdown(&self) -> Result<()> {
Ok(self.0.send(()).await?)
}

pub fn is_finished(&self) -> bool {
self.0.is_closed()
}
}

impl Translator {
Expand Down Expand Up @@ -112,18 +116,21 @@ impl Translator {
let ship_reader_handle = tokio::spawn(ship_reader(ws_rx, raw_ds_tx, self.shutdown_rx));

info!("Translator launched successfully");
let result = join_all(vec![

let handles = vec![
ship_reader_handle,
raw_deserializer_handle,
evm_block_processor_handle,
final_processor_handle,
])
.await;
];

result
join_all(handles)
.await
.into_iter()
.map(|result| result.map_err(From::from))
.collect::<Result<Vec<_>>>()?
.into_iter()
.collect::<std::result::Result<Vec<_>, _>>()
.collect::<Result<Vec<_>>>()
.map(|_| ())
.wrap_err("Failed to execute tasks")
}
}
Loading