File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 15
15
*/
16
16
17
17
use std:: env;
18
- use tokio :: runtime :: Builder ;
18
+
19
19
use containerd_shim:: { asynchronous:: run, parse} ;
20
+ use tokio:: runtime:: Builder ;
20
21
21
22
mod cgroup_memory;
22
23
mod common;
Original file line number Diff line number Diff line change @@ -457,6 +457,9 @@ impl ProcessLifecycle<ExecProcess> for RuncExecLifecycle {
457
457
458
458
async fn delete ( & self , p : & mut ExecProcess ) -> Result < ( ) > {
459
459
self . exit_signal . signal ( ) ;
460
+ self . exit_signal
461
+ . wait_for_exit ( tokio:: time:: Duration :: from_secs ( 2 ) )
462
+ . await ;
460
463
let exec_pid_path = Path :: new ( self . bundle . as_str ( ) ) . join ( format ! ( "{}.pid" , p. id) ) ;
461
464
remove_file ( exec_pid_path) . await . unwrap_or_default ( ) ;
462
465
Ok ( ( ) )
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ use nix::{
47
47
unistd:: Pid ,
48
48
} ;
49
49
use signal_hook_tokio:: Signals ;
50
- use tokio:: { io:: AsyncWriteExt , sync:: Notify } ;
50
+ use tokio:: { self , io:: AsyncWriteExt , sync:: Notify , time :: Duration } ;
51
51
52
52
use crate :: {
53
53
args,
@@ -237,6 +237,22 @@ impl ExitSignal {
237
237
notified. await ;
238
238
}
239
239
}
240
+
241
+ /// Wait for the exit signal to be set or return after a timeout.
242
+ pub async fn wait_for_exit ( & self , timeout_duration : Duration ) {
243
+ let timeout_task = async {
244
+ tokio:: time:: sleep ( timeout_duration) . await ;
245
+ } ;
246
+
247
+ let exit_task = async {
248
+ self . wait ( ) . await ;
249
+ } ;
250
+
251
+ tokio:: select! {
252
+ _ = timeout_task => { } ,
253
+ _ = exit_task => { } ,
254
+ }
255
+ }
240
256
}
241
257
242
258
/// Spawn is a helper func to launch shim process asynchronously.
You can’t perform that action at this time.
0 commit comments