Skip to content

Revert foreground process changes to fix MacOS piping bug (less and fzf) - #6542

Merged
fdncred merged 1 commit into
nushell:mainfrom
dandavison:6273-revert
Sep 11, 2022
Merged

fdncred merged 1 commit into
nushell:mainfrom
dandavison:6273-revert

Conversation

@dandavison

@dandavison dandavison commented Sep 11, 2022 •

Copy link
Copy Markdown
Contributor

Fixes #6534 #6516 #6496. This PR reverts #6273.

The history is:

  1. In unix like system, set foreground process while running external command #6206 made the name of the running process be correctly advertised to tmux/terminal emulators, as was requested by some users.

  2. However, this caused some crashes: Shell gets suspended #6240, so it was reverted in Fix intermittent test crash #6268.

  3. Try again: in unix like system, set foreground process while running external command #6273 fixed the crashes. However it causes a hang on some systems (mostly MacOS) when piping into less and fzf, (and other programs that use less as their pager such as git, bat, and delta). See Nushell can't handle well with less command on MacOS #6496

It seems to make sense to revert again, since the broken piping is worse than the lack of terminal titles. Note that the released version 0.68.1 has the MacOS piping bug.

Tests

I've tested on MacOS that yes | head -n 999 | fzf and yes | head -n 999 | less hang on main but succeed as expected on this branch.

There wasn't much conflict when making this revert: the diff is the reverse of the original. But if anyone knows of PRs that have merged in the interim and don't make sense with this revert, they should shout out. To check the revert diff I looked at:

let original = "1d18f6947ed092a5adb36c327f7eccb4436130a3"
let revert = "304ee0aadbede0e5146ff3f690acd6509d7a9a0d"
git show $original | save /tmp/original.diff
git diff $revert $"($revert)~1" | save /tmp/revert-reversed.diff
delta /tmp/original.diff /tmp/revert-reversed.diff
  • Add tests that cover your changes, either in the command examples, the crate/tests folder, or in the /tests folder.

It's a difficult area to test and there aren't really tests yet.

  • Try to think about corner cases and various ways how your changes could break. Cover them with tests.

  • If adding tests is not possible, please document in the PR body a minimal example with steps on how to reproduce so one can verify your change works.

  • cargo fmt --all -- --check to check standard code formatting (cargo fmt --all applies these changes)

  • cargo clippy --workspace --features=extra -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect to check that you're using the standard code style

  • cargo test --workspace --features=extra to check that all the tests pass

@fdncred

fdncred commented Sep 11, 2022

Copy link
Copy Markdown
Contributor

thanks

@fdncred
fdncred merged commit 2bb367f into nushell:main Sep 11, 2022
valpackett added a commit to valpackett/nushell that referenced this pull request Sep 19, 2022
valpackett added a commit to valpackett/nushell that referenced this pull request Sep 19, 2022
valpackett added a commit to valpackett/nushell that referenced this pull request Sep 20, 2022
fdncred added a commit that referenced this pull request Sep 29, 2022
* Revert "Revert "Try again: in unix like system, set foreground process while running external command (#6273)" (#6542)"

This reverts commit 2bb367f.

* Make foreground job control hopefully work correctly

These changes are mostly inspired by the glibc manual.

* Fix typo in external command description

* Only restore tty control to shell when no fg procs are left; reuse pgrp

* Rework terminal acquirement code to be like fish

Co-authored-by: Darren Schroeder <[email protected]>
fdncred pushed a commit that referenced this pull request Nov 23, 2026
## Description

Adds a regression test for pipeline signal handling: pressing Ctrl+C
while a pipeline of two external commands is running should interrupt
both of them, and Nushell should carry on with the rest of the script.

The test starts `nu -i` on its own pseudo-terminal, so the externals run
in a foreground process group the way they would in a real terminal.
Both commands trap SIGINT and print a line when they get it. After
Ctrl+C the test expects `producer`, `consumer`, and then `resumed` from
the next statement. Output is read through a separate socket, so
terminal echo can't make the test pass by accident.

To check that it catches the kind of bug described in #6542, I changed
`set_foreground_pid` in `crates/nu-system/src/foreground.rs` so that
every external in a pipeline got its own process group. With that change
the test fails after its 15 second read timeout. With the current code
it passes. I haven't tried it against the older commits mentioned in the
issue.

The test is Unix only (`#[cfg(unix)]`) because it relies on a pty and
process groups.

## User-facing changes (Release notes)

n/a

## Additional notes

Part of #6591. This covers Ctrl+C in a two-command external pipeline.
Other cases from #6542 could follow in separate PRs.
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.

fzf freezes the shell in version 0.68.1

2 participants