File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -1913,8 +1913,13 @@ impl RecentlySeenLoop {
1913
1913
. unwrap ( ) ;
1914
1914
}
1915
1915
1916
- pub ( crate ) fn abort ( self ) {
1916
+ pub ( crate ) async fn abort ( self ) {
1917
1917
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 ( ) ;
1918
1923
}
1919
1924
}
1920
1925
Original file line number Diff line number Diff line change @@ -110,13 +110,14 @@ impl SchedulerState {
110
110
// to allow for clean shutdown.
111
111
context. new_msgs_notify . notify_one ( ) ;
112
112
113
- if let Some ( debug_logging) = context
113
+ let debug_logging = context
114
114
. debug_logging
115
- . read ( )
115
+ . write ( )
116
116
. expect ( "RwLock is poisoned" )
117
- . as_ref ( )
118
- {
117
+ . take ( ) ;
118
+ if let Some ( debug_logging ) = debug_logging {
119
119
debug_logging. loop_handle . abort ( ) ;
120
+ debug_logging. loop_handle . await . ok ( ) ;
120
121
}
121
122
let prev_state = std:: mem:: replace ( & mut * inner, new_state) ;
122
123
context. emit_event ( EventType :: ConnectivityChanged ) ;
@@ -974,9 +975,16 @@ impl Scheduler {
974
975
. await
975
976
. log_err ( context)
976
977
. 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.
977
983
self . ephemeral_handle . abort ( ) ;
984
+ self . ephemeral_handle . await . ok ( ) ;
978
985
self . location_handle . abort ( ) ;
979
- self . recently_seen_loop . abort ( ) ;
986
+ self . location_handle . await . ok ( ) ;
987
+ self . recently_seen_loop . abort ( ) . await ;
980
988
}
981
989
}
982
990
You can’t perform that action at this time.
0 commit comments