Skip to content

Commit fd84136

Browse files
committed
fix: await the tasks after aborting them
1 parent 0fceb27 commit fd84136

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/contact.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1913,8 +1913,13 @@ impl RecentlySeenLoop {
19131913
.unwrap();
19141914
}
19151915

1916-
pub(crate) fn abort(self) {
1916+
pub(crate) async fn abort(self) {
19171917
self.handle.abort();
1918+
1919+
// Await aborted task to ensure the `Future` is dropped
1920+
// with all resources moved inside such as the `Context`
1921+
// reference to `InnerContext`.
1922+
self.handle.await.ok();
19181923
}
19191924
}
19201925

src/scheduler.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,14 @@ impl SchedulerState {
110110
// to allow for clean shutdown.
111111
context.new_msgs_notify.notify_one();
112112

113-
if let Some(debug_logging) = context
113+
let debug_logging = context
114114
.debug_logging
115-
.read()
115+
.write()
116116
.expect("RwLock is poisoned")
117-
.as_ref()
118-
{
117+
.take();
118+
if let Some(debug_logging) = debug_logging {
119119
debug_logging.loop_handle.abort();
120+
debug_logging.loop_handle.await.ok();
120121
}
121122
let prev_state = std::mem::replace(&mut *inner, new_state);
122123
context.emit_event(EventType::ConnectivityChanged);
@@ -974,9 +975,16 @@ impl Scheduler {
974975
.await
975976
.log_err(context)
976977
.ok();
978+
979+
// Abort tasks, then await them to ensure the `Future` is dropped.
980+
// Just aborting the task may keep resources such as `Context` clone
981+
// moved into it indefinitely, resulting in database not being
982+
// closed etc.
977983
self.ephemeral_handle.abort();
984+
self.ephemeral_handle.await.ok();
978985
self.location_handle.abort();
979-
self.recently_seen_loop.abort();
986+
self.location_handle.await.ok();
987+
self.recently_seen_loop.abort().await;
980988
}
981989
}
982990

0 commit comments

Comments
 (0)