File tree 2 files changed +19
-3
lines changed
2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -152,7 +152,6 @@ pub(super) fn exec_monitor(
152
152
// Disable nonblocking assetions as we will not poll the backchannel anymore.
153
153
closure. backchannel . set_nonblocking_assertions ( false ) ;
154
154
155
- std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 10 ) ) ;
156
155
match reason {
157
156
StopReason :: Break ( err) => match err. try_into ( ) {
158
157
Ok ( msg) => {
@@ -171,6 +170,14 @@ pub(super) fn exec_monitor(
171
170
}
172
171
}
173
172
173
+ // Wait for the parent to give us red light before shutting down. This avoids missing
174
+ // output when the monitor exits too quickly.
175
+ let event = retry_while_interrupted ( || backchannel. recv ( ) ) . map_err ( |err| {
176
+ dev_warn ! ( "cannot receive red light from parent: {err}" ) ;
177
+ err
178
+ } ) ?;
179
+ debug_assert_eq ! ( event, MonitorMessage :: ExecCommand ) ;
180
+
174
181
// FIXME (ogsudo): The tty is restored here if selinux is available.
175
182
176
183
// 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 @@ -344,10 +344,19 @@ impl ParentClosure {
344
344
}
345
345
346
346
fn run ( & mut self , registry : EventRegistry < Self > ) -> io:: Result < ExitReason > {
347
- match registry. event_loop ( self ) {
347
+ let result = match registry. event_loop ( self ) {
348
348
StopReason :: Break ( err) | StopReason :: Exit ( ParentExit :: Backchannel ( err) ) => Err ( err) ,
349
349
StopReason :: Exit ( ParentExit :: Command ( exit_reason) ) => Ok ( exit_reason) ,
350
- }
350
+ } ;
351
+ // Send red light to the monitor after processing all events
352
+ retry_while_interrupted ( || self . backchannel . send ( & MonitorMessage :: ExecCommand ) ) . map_err (
353
+ |err| {
354
+ dev_error ! ( "cannot send red light to monitor: {err}" ) ;
355
+ err
356
+ } ,
357
+ ) ?;
358
+
359
+ result
351
360
}
352
361
353
362
/// 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