ockam
ockam copied to clipboard
Shut down Worker/Processor if initialization failed
Observed behavior
Currently, if Worker or Processor return an error from its initialize
function, it's not shut down.
Steps to reproduce
Create a dummy Worker that always fails during initialization.
Desired behavior
Worker/Processor should be stopped
Ockam Version
0.116.0
Hi, may I take this one?
@pradovic sure, go ahead
@SanjoDeundiak Thanks! Finally got the time to take a look.
If I understand correctly the error in processor or worker initialize
function error is just logged by WorkerRelay
.
#[cfg_attr(not(feature = "std"), allow(unused_mut))]
#[cfg_attr(not(feature = "std"), allow(unused_variables))]
async fn run(mut self, mut ctrl_rx: SmallReceiver<CtrlSignal>) {
match self.worker.initialize(&mut self.ctx).await {
Ok(()) => {}
Err(e) => {
error!(
"Failure during '{}' worker initialisation: {}",
self.ctx.address(),
e
);
}
}
If I understood correctly this does not stop the worker, but just logs the error. The proposed solution would be to move on to the worker shutdown and context stop ack, without starting the loop in between:
#[cfg_attr(not(feature = "std"), allow(unused_mut))]
#[cfg_attr(not(feature = "std"), allow(unused_variables))]
async fn run(mut self, mut ctrl_rx: SmallReceiver<CtrlSignal>) {
match self.worker.initialize(&mut self.ctx).await {
Ok(()) => {}
Err(e) => {
error!(
"Failure during '{}' worker initialisation: {}",
self.ctx.address(),
e
);
// call self.shutdown & ctx.send_stop_ack
shutdown_and_stop_ack(&mut processor, &mut ctx, &ctx_addr).await;
return;
}
}
Processor is behaving in the same fashion, so I posted worker as a reference.
I have opened the PR with proposed change: https://github.com/build-trust/ockam/pull/7654. Pls correct me if I am wrong and I will be happy to fix it.