Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: add periodic polling in Reaper #6894

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tokio/src/process/unix/reap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ where
inner: Option<W>,
orphan_queue: Q,
signal: S,
#[cfg(feature = "time")]
interval: Option<crate::time::Interval>,
}

impl<W, Q, S> Deref for Reaper<W, Q, S>
Expand All @@ -45,6 +47,12 @@ where
inner: Some(inner),
orphan_queue,
signal,
#[cfg(feature = "time")]
interval: crate::runtime::scheduler::Handle::current()
.driver()
.time
.as_ref()
.map(|_| crate::time::interval(std::time::Duration::from_secs(1))),
}
}

Expand Down Expand Up @@ -86,6 +94,26 @@ where
// should not cause significant issues with parent futures.
let registered_interest = self.signal.poll_recv(cx).is_pending();

// Signals may coalesce. SIGCHLD is a standard signal.
// According to man signal(7):
// > Standard signals do not queue. If multiple instances of a standard signal
// > are generated while that signal is blocked, then only one instance of
// > the signal is marked as pending (and the signal will be delivered
// > just once when it is unblocked).
// This means the SIGCHLD we are waiting for may be overwritten by
// another signal like SIGHUP or whatever,
// and in this case no one is going to wake us up to poll for maybe a long period.
// Hence, besides polling on signal, here we do a polling at an interval of one second
// as well. This makes sure we will not oversleep longer than one second.
// The result of `poll_tick` does not matter: the only thing necessary
// is to give it `cx` to let it wake us up.
// This "timed wait" approach is also used by tini, which is used by Docker as `init`.
#[cfg(feature = "time")]
let _ = self
.interval
.as_mut()
.map(|interval| interval.poll_tick(cx));

if let Some(status) = self.inner_mut().try_wait()? {
return Poll::Ready(Ok(status));
}
Expand Down
Loading