@@ -11,6 +11,7 @@ use rand::Rng;
11
11
use tokio:: sync:: { oneshot, RwLock , RwLockWriteGuard } ;
12
12
use tokio:: task;
13
13
use tokio_util:: sync:: CancellationToken ;
14
+ use tokio_util:: task:: TaskTracker ;
14
15
15
16
use self :: connectivity:: ConnectivityStore ;
16
17
use crate :: config:: { self , Config } ;
@@ -989,16 +990,26 @@ impl Scheduler {
989
990
990
991
// Actually shutdown tasks.
991
992
let timeout_duration = std:: time:: Duration :: from_secs ( 30 ) ;
993
+
994
+ let tracker = TaskTracker :: new ( ) ;
992
995
for b in once ( self . inbox ) . chain ( self . oboxes ) {
993
- tokio:: time:: timeout ( timeout_duration, b. handle )
994
- . await
995
- . log_err ( context)
996
- . ok ( ) ;
996
+ let context = context. clone ( ) ;
997
+ tracker. spawn ( async move {
998
+ tokio:: time:: timeout ( timeout_duration, b. handle )
999
+ . await
1000
+ . log_err ( & context)
1001
+ } ) ;
997
1002
}
998
- tokio:: time:: timeout ( timeout_duration, self . smtp_handle )
999
- . await
1000
- . log_err ( context)
1001
- . ok ( ) ;
1003
+ {
1004
+ let context = context. clone ( ) ;
1005
+ tracker. spawn ( async move {
1006
+ tokio:: time:: timeout ( timeout_duration, self . smtp_handle )
1007
+ . await
1008
+ . log_err ( & context)
1009
+ } ) ;
1010
+ }
1011
+ tracker. close ( ) ;
1012
+ tracker. wait ( ) . await ;
1002
1013
1003
1014
// Abort tasks, then await them to ensure the `Future` is dropped.
1004
1015
// Just aborting the task may keep resources such as `Context` clone
0 commit comments