Skip to content

sort: handle compression subprocess failures - #14945

Open
mattsu2020 wants to merge 3 commits into
uutils:mainfrom
mattsu2020:sort-compress-proc.sh
Open

mattsu2020 wants to merge 3 commits into
uutils:mainfrom
mattsu2020:sort-compress-proc.sh

Conversation

@mattsu2020

@mattsu2020 mattsu2020 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Compression subprocesses that exit early can terminate sort with SIGPIPE, and intermediate merge write failures can return status 1 instead of 2. Handle broken pipes and buffered write errors, reject abnormal child exits, and wait for compression and decompression children on error paths. Restore child waiting when SIGCHLD is inherited as ignored, while preserving normal SIGPIPE behavior for stdout.

Adds regression tests for early exits, failures after consuming all input or producing output, signal termination, and intermediate merge failures. The sort regression tests pass on macOS and Linux. The GNU shell test itself has not been run.

The current CodSpeed comparison mixes Rust 1.98.1 and 1.99.0 between BASE and HEAD. Paired Linux/aarch64 runs using Rust 1.99.0 did not reproduce the reported large sort and split slowdowns; a matched-toolchain CodSpeed comparison is still needed.

Refs #14705 (sort/sort-compress-proc.sh).
Closes #14951

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/misc/usage_vs_getopt (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/pr/options is no longer failing!

@mattsu2020
mattsu2020 marked this pull request as draft September 29, 2026 11:06
@xtqqczze

This comment was marked as resolved.

@mattsu2020
mattsu2020 marked this pull request as ready for review September 29, 2026 13:09
Comment thread src/uu/sort/src/merge.rs Resolved
Comment thread src/uu/sort/src/merge.rs Resolved
Comment thread src/uu/sort/src/merge.rs Resolved
Comment thread src/uu/sort/src/merge.rs Resolved
Comment thread tests/by-util/test_sort.rs Resolved
Comment thread tests/by-util/test_sort.rs Resolved
@mattsu2020
mattsu2020 marked this pull request as draft October 8, 2026 12:02
@mattsu2020
mattsu2020 force-pushed the sort-compress-proc.sh branch from c9fe52e to 8d968cb Compare October 8, 2026 12:55
@codspeed

codspeed Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 12.95%

1 warning, 1 note

⚠️ 122 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

❌ 2 regressed benchmarks
✅ 413 untouched benchmarks
⏩ 70 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ CPU Simulation socket_addrs_direct[100000] 105.3 µs 132 µs -20.24%
❌ CPU Simulation hostname_ip_lookup[100000] 546.9 µs 575.7 µs -5%

Tip

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


Comparing mattsu2020:sort-compress-proc.sh (ec60f02) with main (887b9e6)2

Open in CodSpeed

Footnotes

  1. 70 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. ↩

  2. No successful run was found on main (7b68df0) during the generation of this report, so 887b9e6 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@sylvestre

Copy link
Copy Markdown
Contributor

significant perf regressions here

@mattsu2020
mattsu2020 marked this pull request as ready for review October 8, 2026 14:08
Comment thread src/uu/sort/src/merge.rs Resolved
/// Consumes a newly generated SIGPIPE on EPIPE, preserving any already pending
/// signal and restoring the original mask even if the operation panics.
#[cfg(all(unix, not(target_vendor = "apple")))]
pub fn with_sigpipe_blocked<T>(write: impl FnOnce() -> std::io::Result<T>) -> std::io::Result<T> {

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.

that's 4+ syscalls per buffered write (mask swap, 2 sigpending, restore), could we block SIGPIPE once around the whole tmp file write instead?

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.

I'll simplify the implementation

Comment thread src/uucore/src/lib/features/signals.rs Resolved
Comment thread tests/by-util/test_sort.rs Resolved
@mattsu2020
mattsu2020 marked this pull request as draft October 8, 2026 22:26
@mattsu2020
mattsu2020 marked this pull request as ready for review October 8, 2026 23:04
@mattsu2020
mattsu2020 force-pushed the sort-compress-proc.sh branch from f9bc89c to 8086e84 Compare November 12, 2026 11:23
@mattsu2020
mattsu2020 requested a review from sylvestre November 12, 2026 11:24
@mattsu2020
mattsu2020 marked this pull request as draft November 22, 2026 23:18
@mattsu2020
mattsu2020 force-pushed the sort-compress-proc.sh branch from 8086e84 to afa5d26 Compare November 22, 2026 23:31
@mattsu2020
mattsu2020 marked this pull request as ready for review November 22, 2026 23:32
Comment thread tests/by-util/test_sort.rs Outdated
}

#[cfg(unix)]
fn run_with_compressor(script: &str, input: &str, buffer_size: &str, expected_error: &str) {

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.

these #!/bin/sh scripts will break on android (no /bin/sh there), test_compress_fail is skipped on android for that, probably the Android CI failure, 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.

fixed it.
Changed /bin/sh handling for Android.

fn test_compress_failures_ignored_sigchld() {
let ts = TestScenario::new("sort");
ts.fixtures.write("input", &compressor_input(600, 4, ""));
for script in [

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.

same three scripts as test_compressor_failure_after_input / _terminated_by_signal / _failure_after_output, could be dedup, 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.

Consolidated similar logic.

Comment thread src/uu/sort/src/merge.rs Outdated
use std::os::unix::fs::PermissionsExt;

#[test]
fn compression_pipe_final_flush_error() {

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.

re-exec of the test binary, unwraps, env var modes... quite complex for a unit test, could it be an integration test in test_sort.rs instead?

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.

fixed it

@mattsu2020
mattsu2020 marked this pull request as draft November 23, 2026 12:03
@mattsu2020
mattsu2020 force-pushed the sort-compress-proc.sh branch from 5937cc0 to d2069ff Compare November 23, 2026 12:08
@mattsu2020
mattsu2020 marked this pull request as ready for review November 23, 2026 12:09
@sylvestre
sylvestre force-pushed the sort-compress-proc.sh branch 4 times, most recently from 58ffb04 to ec60f02 Compare November 29, 2026 00:38
Keep pipe failures local to temporary file writes without changing stdout or child signal behavior. Cover pending signals, unwinding, and inherited SIGCHLD dispositions in unit tests.
Report temporary write and flush failures with status 2, reject abnormal child exits, and reap compression children on error paths. Add regression tests for early exits, signals, intermediate merges, and closed stdout.
@sylvestre
sylvestre force-pushed the sort-compress-proc.sh branch from ec60f02 to 5e1fe6e Compare November 29, 2026 19:52

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.

sort: handle compression subprocess failures

3 participants