uutils / uutils/coreutils

sort aborts instead of exiting non-zero when a temp-file write fails during external-sort spill

Open Beginner friendly
#14,377 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

U - sort
Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Description

When sort spills sorted chunks to temporary files during an external sort (any time the input exceeds the sort buffer), it writes each chunk with write_all(...).unwrap(). If that temp-file write fails — e.g. the -T temp directory is on a full or size-limited filesystem — the unwrap() panics.

This is distinct from #13653 ("sort aborts … when the output write fails during a merge"): that was the output write path (merge.rs) and was fixed by #13654, which touched only merge.rs. The temp-file spill write in ext_sort/threaded.rs was not covered and still aborts at current main.

Steps to reproduce

Point -T at a small filesystem and force a spill with a tiny buffer (-S 0).
Using a 1 MiB tmpfs as the temp dir; output goes to /dev/null, so it is the
temp-file write that fails, not the output:

$ # ~18 MB of shuffled lines
$ python3 -c "import random; open('big.txt','w').write(''.join(f'{random.randint(0,10**9):09d}-padding-payload\n' for _ in range(400000)))"

$ # temp dir on a 1 MiB tmpfs (e.g. mount -t tmpfs -o size=1m tmpfs /st)
$ sort -S 0 -T /st big.txt -o /dev/null
thread 'main' panicked at src/uu/sort/src/ext_sort/threaded.rs:302:34:
called `Result::unwrap()` on an `Err` value: Os { code: 28, kind: StorageFull, message: "No space left on device" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Aborted (core dumped)
$ echo $?
134

Root cause

The chunk-spill writer unwraps every temp-file write:

https://github.com/uutils/coreutils/blob/5426f41b62ec27692ab043b3807306f3a6b5361b/src/uu/sort/src/ext_sort/threaded.rs#L300-L305

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/uu/sort/src/ext_sort/threaded.rs around lines 300-305, where spilled chunks are written, and reproduce the failure with a small -T filesystem and -S 0. Confirm that a temp-file write failure exits non-zero without panicking or aborting, while output still goes to /dev/null.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.