sort aborts instead of exiting non-zero when a temp-file write fails during external-sort spill
Nobody has claimed this yet.
- 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:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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