fish-shell / fish-shell/fish-shell
Builtins writing to stdout don't abort when stdout has closed
- Dominant language
- Rust
- Stars
- 34.2k
- Forks
- 2.4k
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 13
Description
Using `head` to terminate long-running command after x lines is a common idiom. Here, it's used to stop reading a terabyte log file after sufficient matches are found via `grep`:
```
> tac /hddpool/nginx.access.log | grep -i keep-alive | head -n8
# to stdout, from `grep`
/hddpool/nginx.access.log: Os { code: 32, kind: BrokenPipe, message: "Broken pipe" } # to stderr, from `tac`
```
but with `string match` instead of grep:
```
> tac /hddpool/nginx.access.log | string match -ei keep-alive | head -n8
# to stdout, from `grep`
# script hangs here w/ `tac` running but `head` aborted (currently a zombie)
```
When stdout is closed, builtins need to terminate and then exit (closing their `stdin` in the process).
I already patched all the builtin write functions to return success/failure in 3.6.0, but we're going to need to start checking the return code in each builtin as it writes to stdout so we can abort early.
Contributor guide
Assessment
This issue has not been assessed yet.