@@ -159,52 +159,56 @@ async fn process_exits(
159
159
if let Subject :: Pid ( pid) = e. subject {
160
160
debug ! ( "receive exit event: {}" , & e) ;
161
161
let exit_code = e. exit_code ;
162
- for ( _k , cont ) in containers. lock ( ) . await . iter_mut ( ) {
163
- let bundle = cont . bundle . to_string ( ) ;
164
- // pid belongs to container init process
165
- if cont. init . pid == pid {
166
- // kill all children process if the container has a private PID namespace
167
- if should_kill_all_on_exit ( & bundle ) . await {
168
- cont. kill ( None , 9 , true ) . await . unwrap_or_else ( |e| {
169
- error ! ( "failed to kill init's children: {}" , e )
170
- } ) ;
171
- }
172
- // set exit for init process
173
- cont . init . set_exited ( exit_code ) . await ;
174
-
175
- // publish event
176
- let ( _ , code , exited_at ) = match cont. get_exit_info ( None ) . await {
177
- Ok ( info ) => info ,
178
- Err ( _ ) => break ,
179
- } ;
180
-
181
- let ts = convert_to_timestamp ( exited_at ) ;
182
- let event = TaskExit {
183
- container_id : cont . id . to_string ( ) ,
184
- id : cont . id . to_string ( ) ,
185
- pid : cont . pid ( ) . await as u32 ,
186
- exit_status : code as u32 ,
187
- exited_at : Some ( ts ) . into ( ) ,
188
- .. Default :: default ( )
189
- } ;
190
- let topic = event . topic ( ) ;
191
- tx . send ( ( topic . to_string ( ) , Box :: new ( event ) ) )
192
- . await
193
- . unwrap_or_else ( |e| warn ! ( "send {} to publisher: {}" , topic, e ) ) ;
194
-
195
- break ;
196
- }
162
+ let containers = containers. clone ( ) ;
163
+ let tx = tx . clone ( ) ;
164
+ tokio :: spawn ( async move {
165
+ for ( _k , cont) in containers . lock ( ) . await . iter_mut ( ) {
166
+ let bundle = cont . bundle . to_string ( ) ;
167
+ // pid belongs to container init process
168
+ if cont. init . pid == pid {
169
+ // kill all children process if the container has a private PID namespace
170
+ if should_kill_all_on_exit ( & bundle ) . await {
171
+ cont . kill ( None , 9 , true ) . await . unwrap_or_else ( |e| {
172
+ error ! ( "failed to kill init's children: {}" , e )
173
+ } ) ;
174
+ }
175
+ // set exit for init process
176
+ cont. init . set_exited ( exit_code ) . await ;
177
+
178
+ // publish event
179
+ let ( _ , code , exited_at ) = match cont . get_exit_info ( None ) . await {
180
+ Ok ( info ) => info ,
181
+ Err ( _ ) => break ,
182
+ } ;
183
+
184
+ let ts = convert_to_timestamp ( exited_at ) ;
185
+ let event = TaskExit {
186
+ container_id : cont . id . to_string ( ) ,
187
+ id : cont . id . to_string ( ) ,
188
+ pid : cont . pid ( ) . await as u32 ,
189
+ exit_status : code as u32 ,
190
+ exited_at : Some ( ts ) . into ( ) ,
191
+ .. Default :: default ( )
192
+ } ;
193
+ let topic = event . topic ( ) ;
194
+ tx . send ( ( topic . to_string ( ) , Box :: new ( event ) ) )
195
+ . await
196
+ . unwrap_or_else ( |e| warn ! ( "send {} to publisher: {}" , topic , e ) ) ;
197
197
198
- // pid belongs to container common process
199
- for ( _exec_id, p) in cont. processes . iter_mut ( ) {
200
- // set exit for exec process
201
- if p. pid == pid {
202
- p. set_exited ( exit_code) . await ;
203
- // TODO: publish event
204
198
break ;
205
199
}
200
+
201
+ // pid belongs to container common process
202
+ for ( _exec_id, p) in cont. processes . iter_mut ( ) {
203
+ // set exit for exec process
204
+ if p. pid == pid {
205
+ p. set_exited ( exit_code) . await ;
206
+ // TODO: publish event
207
+ break ;
208
+ }
209
+ }
206
210
}
207
- }
211
+ } ) ;
208
212
}
209
213
}
210
214
monitor_unsubscribe ( s. id ) . await . unwrap_or_default ( ) ;
0 commit comments