Repository navigation
timeout: do not escalate to KILL when non-TERM signal ends child - #16716
Open
yunusarda-sudo wants to merge 1 commit into
Open
yunusarda-sudo wants to merge 1 commit into
yunusarda-sudo wants to merge 1 commit into
Conversation
When -k is specified, timeout enters wait_or_kill_process to wait through the grace period. Because timeout broadcasts the timeout signal to the process group, timeout receives the signal itself. Previously, wait_or_timeout only ignored SIGTERM, causing other signals (such as SIGINT, SIGHUP, SIGQUIT) to immediately return TimeoutRet::Interrupted and trigger an immediate SIGKILL even if the child process was already terminated. Fix this by passing the specific signal to wait_or_timeout to ignore, and verifying whether the child has already exited before sending SIGKILL. Fixes uutils#16642
sylvestre
reviewed
Nov 19, 2026
| } | ||
| // GNU timeout also kills on signals other than SIGTERM. | ||
| Ok(TimeoutRet::TimedOut | TimeoutRet::Interrupted(_)) => { | ||
| if let Some(status) = process.try_wait()? { |
Contributor
There was a problem hiding this comment.
is this still needed with the ignore_signal change? it duplicates the Exited arm just above
| /// | ||
| /// If there is a problem sending the `SIGKILL` signal or waiting for | ||
| /// the process after that signal is sent. | ||
| #[allow(clippy::too_many_arguments)] |
Contributor
There was a problem hiding this comment.
please avoid the #[allow]. ignore_signal is always Some here, so it could just be the signal we sent, or the args could be grouped
| drop(self.stdin.take()); | ||
|
|
||
| // Fast path: if the child already terminated, return its exit status immediately. | ||
| if let Some(status) = self.try_wait()? { |
Contributor
There was a problem hiding this comment.
why do we need this fast path? SIGCHLD already handles it
| match timer.timed_sigwait(remaining) { | ||
| Ok(None) => break Ok(TimeoutRet::TimedOut), | ||
| Ok(None) => { | ||
| if let Some(status) = self.try_wait()? { |
Contributor
There was a problem hiding this comment.
same here, do we need this try_wait?
| } // otherwise waits again | ||
| } | ||
| Ok(Some(Signal::SIGTERM)) if ignore_term => {} // waits again | ||
| Ok(Some(signal)) if ignore_signal == Some(signal as usize) => {} // waits again |
Contributor
There was a problem hiding this comment.
with -s INT, an external TERM during the grace period now escalates to KILL, before it was ignored. is that intended?
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
-k(kill-after grace period) is used with a non-TERM timeout signal (such as-s INT,-s HUP, or-s QUIT),timeoutsends that signal to the child's process group. Becausetimeoutis also in that process group, it receives the signal itself as a pending signal.During the kill-after grace period,
wait_or_kill_processinvokeswait_or_timeout. Previously,wait_or_timeoutonly ignoredSIGTERM(ignore_term: bool). As a result, receiving any non-TERM signal immediately causedwait_or_timeoutto returnTimeoutRet::Interrupted, whichwait_or_kill_processtreated as an immediate prompt to sendSIGKILL, overriding the child's normal termination and reporting command timed out / killed.This PR fixes this by:
ChildExt::wait_or_timeoutto acceptignore_signal: Option<usize>, ignoring the specific signal that was broadcast to the process group during the grace period.process.try_wait()?before escalating toSIGKILLinwait_or_kill_process.tests/by-util/test_timeout.rsverifying that non-TERM signals (INT, HUP, QUIT) with-kdo not escalate to KILL when the child exits cleanly.Fixes #16642