Skip to content

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

Description

@leeewee

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:

fn write_lines<T: Write>(lines: &[Line], writer: &mut T, separator: u8) {
for s in lines {
writer.write_all(s.line).unwrap();
writer.write_all(&[separator]).unwrap();
}
}

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions