Skip to content

timeout: return 128 + signal with --preserve-status and --kill-after - #15175

Open
SichenLiang wants to merge 3 commits into
uutils:mainfrom
SichenLiang:timeout-preserve-status-kill-after
Open

SichenLiang wants to merge 3 commits into
uutils:mainfrom
SichenLiang:timeout-preserve-status-kill-after

Conversation

@SichenLiang

@SichenLiang SichenLiang commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

With --kill-after, if COMMAND died from the first timeout signal before KILL was needed, --preserve-status returned the signal number by itself. The path without --kill-after already returned 128 + signal, which is also what GNU does.

$ timeout --preserve-status --kill-after=5 1 sleep 5; echo $?
143

This printed 15 before. --foreground -s HUP had the same problem: it returned 1 before and now returns 129.

Closes #15178

@xtqqczze

xtqqczze commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

Please open an issue to track the work.

@SichenLiang

Copy link
Copy Markdown
Contributor Author

Opened #15178 for it.

Comment thread src/uu/timeout/src/timeout.rs Outdated
if preserve_status {
let exit_code = status.code().unwrap_or_else(|| {
platform::status_signal(status).unwrap_or_else(|| {
let exit_code = status

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost the same code as in timeout() below, could be dedup into a small helper, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, moved into small preserved_exit_code helper

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/resolution (fails in this run but passes in the 'main' branch)

@codspeed

codspeed Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 5.74%

⚠️ 116 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

ℹ️ 1 benchmark has no flame graph

The flamegraph could not be generated because too much time was spent in runtime internals, making the visualization not useful for performance analysis.

⚡ 1 improved benchmark
❌ 2 regressed benchmarks
✅ 398 untouched benchmarks
⏩ 54 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Simulation three_39_bit_primes 498 ms 591.1 ms -15.75%
❌ Simulation five_38_bit_primes 1.7 s 1.8 s -5.45%
⚡ Simulation thirteen_39_bit_primes 9.8 s 9.3 s +5.14%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing SichenLiang:timeout-preserve-status-kill-after (a5abc39) with main (7bc1eb6)

Open in CodSpeed

Footnotes

  1. 54 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Comment thread src/uu/timeout/src/timeout.rs Outdated
// This can happen on some platforms or in unusual termination scenarios.
ExitStatus::TimeoutFailed.into()
});
let exit_code = preserved_exit_code(status).unwrap_or_else(|| {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use unwrap_or instead of unwrap_or_else when the fallback is an inexpensive expression that doesn’t benefit from lazy evaluation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to unwrap_or, thanks!

When --kill-after was set and the command died from the first timeout
signal, the preserve-status path returned the bare signal number.
SIGTERM, for example, gave status 15 instead of 143.

Return 128 + signal here, as timeout already does without --kill-after
and as GNU does.
`ExitStatus::TimeoutFailed.into()` is an inexpensive fixed value, so
there is no need to build it through an `unwrap_or_else` closure.
@sylvestre
sylvestre force-pushed the timeout-preserve-status-kill-after branch from a5abc39 to ccdf89f Compare November 23, 2026 18:33

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

timeout: --preserve-status with --kill-after returns the signal number instead of 128+signal

3 participants