File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -168,7 +168,6 @@ pub(super) fn exec_monitor(
168
168
// Disable nonblocking assetions as we will not poll the backchannel anymore.
169
169
closure. backchannel . set_nonblocking_assertions ( false ) ;
170
170
171
- std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 10 ) ) ;
172
171
match reason {
173
172
StopReason :: Break ( err) => match err. try_into ( ) {
174
173
Ok ( msg) => {
@@ -187,6 +186,14 @@ pub(super) fn exec_monitor(
187
186
}
188
187
}
189
188
189
+ // Wait for the parent to give us red light before shutting down. This avoids missing
190
+ // output when the monitor exits too quickly.
191
+ let event = retry_while_interrupted ( || backchannel. recv ( ) ) . map_err ( |err| {
192
+ dev_warn ! ( "cannot receive red light from parent: {err}" ) ;
193
+ err
194
+ } ) ?;
195
+ debug_assert_eq ! ( event, MonitorMessage :: ExecCommand ) ;
196
+
190
197
// FIXME (ogsudo): The tty is restored here if selinux is available.
191
198
192
199
// We call `_exit` instead of `exit` to avoid flushing the parent's IO streams by accident.
Original file line number Diff line number Diff line change @@ -349,10 +349,19 @@ impl ParentClosure {
349
349
}
350
350
351
351
fn run ( & mut self , registry : EventRegistry < Self > ) -> io:: Result < ExitReason > {
352
- match registry. event_loop ( self ) {
352
+ let result = match registry. event_loop ( self ) {
353
353
StopReason :: Break ( err) | StopReason :: Exit ( ParentExit :: Backchannel ( err) ) => Err ( err) ,
354
354
StopReason :: Exit ( ParentExit :: Command ( exit_reason) ) => Ok ( exit_reason) ,
355
- }
355
+ } ;
356
+ // Send red light to the monitor after processing all events
357
+ retry_while_interrupted ( || self . backchannel . send ( & MonitorMessage :: ExecCommand ) ) . map_err (
358
+ |err| {
359
+ dev_error ! ( "cannot send red light to monitor: {err}" ) ;
360
+ err
361
+ } ,
362
+ ) ?;
363
+
364
+ result
356
365
}
357
366
358
367
/// Read an event from the backchannel and return the event if it should break the event loop.
You can’t perform that action at this time.
0 commit comments