From 8cc348bfa45c1a0a4bf55f9bf95e583ce0a5dd67 Mon Sep 17 00:00:00 2001 From: link2xt Date: Wed, 13 Mar 2024 15:12:22 +0000 Subject: [PATCH] fix: terminate ephemeral and location loop immediately on channel close When scheduler is destroyed, e.g. during a key import, there is some time between destroying the interrupt channel and the loop task. To avoid busy looping, tasks should terminate if receiving from the interrupt loop fails instead of treating it as the interrupt. --- src/ephemeral.rs | 18 +++++++++++++++--- src/location.rs | 16 +++++++++++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/ephemeral.rs b/src/ephemeral.rs index 9146698c1..15fe7e6cb 100644 --- a/src/ephemeral.rs +++ b/src/ephemeral.rs @@ -569,9 +569,21 @@ pub(crate) async fn ephemeral_loop(context: &Context, interrupt_receiver: Receiv "Ephemeral loop waiting for deletion in {} or interrupt", duration_to_str(duration) ); - if timeout(duration, interrupt_receiver.recv()).await.is_ok() { - // received an interruption signal, recompute waiting time (if any) - continue; + match timeout(duration, interrupt_receiver.recv()).await { + Ok(Ok(())) => { + // received an interruption signal, recompute waiting time (if any) + continue; + } + Ok(Err(err)) => { + warn!( + context, + "Interrupt channel closed, ephemeral loop exits now: {err:#}." + ); + return; + } + Err(_err) => { + // Timeout. + } } } diff --git a/src/location.rs b/src/location.rs index 95e6a7ffd..879bd27e4 100644 --- a/src/location.rs +++ b/src/location.rs @@ -679,7 +679,21 @@ pub(crate) async fn location_loop(context: &Context, interrupt_receiver: Receive "Location loop is waiting for {} or interrupt", duration_to_str(duration) ); - timeout(duration, interrupt_receiver.recv()).await.ok(); + match timeout(duration, interrupt_receiver.recv()).await { + Err(_err) => { + info!(context, "Location loop timeout."); + } + Ok(Err(err)) => { + warn!( + context, + "Interrupt channel closed, location loop exits now: {err:#}." + ); + return; + } + Ok(Ok(())) => { + info!(context, "Location loop received interrupt."); + } + } } }