Skip to content

Nushell can't handle well with less command on MacOS #6496

Closed

Description

@WindSoilder

Describe the bug

Refer to the comment: #6273 (comment)

Create the issue to not lost it.

How to reproduce

  1. yes | head -n 999 | with-env [LESS ""] { less }
  2. should exit on q but doesn't exit

Expected behavior

after type q, should exit less command.

Screenshots

No response

Configuration

key value
version 0.67.1
branch
commit_hash e81689f
build_os macos-x86_64
build_target x86_64-apple-darwin
rust_version rustc 1.62.0 (a8314ef7d 2022-06-27)
rust_channel stable-x86_64-apple-darwin
cargo_version cargo 1.62.0 (a748cf5a3 2022-06-08)
pkg_version 0.67.1
build_time 2022-09-04 14:51:48 +08:00
build_rust_channel release
features database, dataframe, default, trash, which, zip
installed_plugins

Additional context

It only happened on MacOS, introduced by #6273

Activity

  1. sholderbach commented on Sep 6, 2022

    @sholderbach
    Member

    Does it affect the termination of other programms that are taking STDIN? e.g. piping into vim etc?

  2. added
    category:bug
    deprecated:platform-specific
    status:investigate
    A:external-commands
    on Sep 6, 2022
  3. WindSoilder commented on Sep 7, 2022

    @WindSoilder
    ContributorAuthor

    Maybe, but currently I'm not sure about that...

  4. dandavison commented on Sep 7, 2022

    @dandavison
    Contributor

    I believe that the bug involves processes in the pipeline terminating before we expect them to.

    When we do ^yes | LESS= ^less, then this works correctly: it quits on q. Before quitting, the process tree shows that yes is still running:

    GOOD:

     |-+= 38392 ddavison /System/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal
     | \-+= 38393 root login -pf ddavison
     |   \-+= 38394 ddavison -zsh
     |     \-+= 39033 ddavison nu
     |       |--= 39970 ddavison yes
     |       \--= 39971 ddavison less
    

    However, when an additional process is present in the pipeline, such as ^yes | ^head -n 999 | LESS= ^less then it does not quit on q and the process tree shows that both yes and head have exited:

    BAD:

     |-+= 38392 ddavison /System/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal
     | \-+= 38393 root login -pf ddavison
     |   \-+= 38394 ddavison -zsh
     |     \-+= 39033 ddavison nu
     |       \--= 39898 ddavison less
    

    The above commands are very consistent for me, but with other commands the bug sometimes appears and sometimes doesn't.

    Another thing I don't understand is that ^yes | ^cat | LESS= ^less seems to work fine, but what's the difference between cat and head?

    GOOD:

     | \-+= 38393 root login -pf ddavison
     |   \-+= 38394 ddavison -zsh
     |     \-+= 39033 ddavison nu
     |       |--= 40664 ddavison yes
     |       |--= 40665 ddavison cat
     |       \--= 40666 ddavison less
    
  5. dandavison commented on Sep 7, 2022

    @dandavison
    Contributor

    Does it affect the termination of other programms that are taking STDIN? e.g. piping into vim etc?

    I am also not sure but I tentatively think that it may be a race condition that we only see when the pager is holding the pipeline open. For example, I cannot reproduce it like this:

    GOOD:

    ~ 〉^yes | ^head -n 999 | python -c 'print(__import__("sys").stdin.read().splitlines()[:2])'
    ['y', 'y']
    

    (In addition to less, this bug also affects programs like bat and delta that pipe their output to less automatically.)

  6. WindSoilder commented on Sep 7, 2022

    @WindSoilder
    ContributorAuthor

    One more thing unfortunally, since the relative implementation is mostly based on ion(https://gitlab.redox-os.org/redox-os/ion), I tried and found that ion also had this problem...

  7. sholderbach commented on Sep 7, 2022

    @sholderbach
    Member

    Would you mind dumping the file descriptors that the involved processes hold when they are stalled with

    lsof -p <PID of process>

  8. dandavison commented on Sep 7, 2022

    @dandavison
    Contributor

    Would you mind dumping the file descriptors that the involved processes hold when they are stalled

    Of course, no problem.

    GOOD (yes is alive in the pipeline and q will work):

    yes | LESS= less
    
     |-+= 38392 ddavison /System/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal
     | \-+= 38393 root login -pf ddavison
     |   \-+= 38394 ddavison -zsh
     |     \-+= 57766 ddavison nu
     |       |--= 57838 ddavison yes
     |       \--= 57839 ddavison less -S
    

    [EDIT: The -S flag is creeping in there because I used less instead of ^less and it picked up an alias that adds the -S flag. I don't think this detail is relevant to our main discussion; I've tried with and without -S and bug behavior is the same. ]

    ~/tmp/3p/nushell/nushell main 〉lsof -p 57766
    COMMAND   PID     USER   FD     TYPE             DEVICE SIZE/OFF                NODE NAME
    nu      57766 ddavison  cwd      DIR                1,5     3904              341671 /Users/ddavison
    nu      57766 ddavison  txt      REG                1,5 22951464           129779054 /Users/ddavison/tmp/3p/nushell/nushell/target/release/nu
    nu      57766 ddavison  txt      REG                1,5  2177216 1152921500312782999 /usr/lib/dyld
    nu      57766 ddavison    0u     CHR               16,0 0t189626                2079 /dev/ttys000
    nu      57766 ddavison    1u     CHR               16,0 0t189626                2079 /dev/ttys000
    nu      57766 ddavison    2u     CHR               16,0 0t189626                2079 /dev/ttys000
    nu      57766 ddavison    3     PIPE 0x179ee492cdf0885b    16384                     ->0x8c82085da032fb8b
    nu      57766 ddavison    4     PIPE 0x8c82085da032fb8b    16384                     ->0x179ee492cdf0885b
    nu      57766 ddavison    5u  KQUEUE                                                 count=0, state=0x8
    nu      57766 ddavison    6u    unix 0x2686700d9a19e0cb      0t0                     ->0x2686700d9a19e25b
    nu      57766 ddavison    7u    unix 0x2686700d9a19e25b      0t0                     ->0x2686700d9a19e0cb
    nu      57766 ddavison    8     PIPE 0xb582f8ec54d853ac    65536                     ->0xab685d34ebfb3dc2
    nu      57766 ddavison   10     PIPE 0x2d0f57a7ee0fa87d    65536                     ->0xb19b1f9c610c76eb
    
    ~/tmp/3p/nushell/nushell main 〉lsof -p 57838
    COMMAND   PID     USER   FD   TYPE             DEVICE SIZE/OFF                NODE NAME
    gyes    57838 ddavison  cwd    DIR                1,5     3904              341671 /Users/ddavison
    gyes    57838 ddavison  txt    REG                1,5    91656           122158633 /usr/local/Cellar/coreutils/9.1/bin/gyes
    gyes    57838 ddavison  txt    REG                1,5  2177216 1152921500312782999 /usr/lib/dyld
    gyes    57838 ddavison    0u   CHR               16,0 0t189626                2079 /dev/ttys000
    gyes    57838 ddavison    1   PIPE 0xab685d34ebfb3dc2    65536                     ->0xb582f8ec54d853ac
    gyes    57838 ddavison    2u   CHR               16,0 0t189626                2079 /dev/ttys000
    
    ~/tmp/3p/nushell/nushell main 〉lsof -p 57839
    COMMAND   PID     USER   FD   TYPE             DEVICE SIZE/OFF                NODE NAME
    less    57839 ddavison  cwd    DIR                1,5     3904              341671 /Users/ddavison
    less    57839 ddavison  txt    REG                1,5   278512            17652894 /Users/ddavison/tmp/3p/less/less
    less    57839 ddavison  txt    REG                1,5  2177216 1152921500312782999 /usr/lib/dyld
    less    57839 ddavison    0   PIPE 0xb19b1f9c610c76eb    65536                     ->0x2d0f57a7ee0fa87d
    less    57839 ddavison    1u   CHR               16,0 0t189626                2079 /dev/ttys000
    less    57839 ddavison    2u   CHR               16,0 0t189626                2079 /dev/ttys000
    less    57839 ddavison    3r   CHR               16,0      0t0                2079 /dev/ttys000
    
  9. dandavison commented on Sep 7, 2022

    @dandavison
    Contributor

    BAD: ( yes has exited and q will not work)

    ^yes | ^head -n 999 | LESS= ^less
    
     |-+= 38392 ddavison /System/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal
     | \-+= 38393 root login -pf ddavison
     |   \-+= 38394 ddavison -zsh
     |     \-+= 57766 ddavison nu
     |       \--= 58147 ddavison less
    
    ~/tmp/3p/nushell/nushell main 〉lsof -p 57766
    COMMAND   PID     USER   FD     TYPE             DEVICE SIZE/OFF                NODE NAME
    nu      57766 ddavison  cwd      DIR                1,5     3904              341671 /Users/ddavison
    nu      57766 ddavison  txt      REG                1,5 22951464           129779054 /Users/ddavison/tmp/3p/nushell/nushell/target/release/nu
    nu      57766 ddavison  txt      REG                1,5  2177216 1152921500312782999 /usr/lib/dyld
    nu      57766 ddavison    0u     CHR               16,0 0t191568                2079 /dev/ttys000
    nu      57766 ddavison    1u     CHR               16,0 0t191568                2079 /dev/ttys000
    nu      57766 ddavison    2u     CHR               16,0 0t191568                2079 /dev/ttys000
    nu      57766 ddavison    3     PIPE 0x179ee492cdf0885b    16384                     ->0x8c82085da032fb8b
    nu      57766 ddavison    4     PIPE 0x8c82085da032fb8b    16384                     ->0x179ee492cdf0885b
    nu      57766 ddavison    5u  KQUEUE                                                 count=1, state=0x8
    nu      57766 ddavison    6u    unix 0x2686700d9a19e0cb      0t0                     ->0x2686700d9a19e25b
    nu      57766 ddavison    7u    unix 0x2686700d9a19e25b      0t0                     ->0x2686700d9a19e0cb
    
    ~/tmp/3p/nushell/nushell main 〉lsof -p 58147
    COMMAND   PID     USER   FD   TYPE             DEVICE SIZE/OFF                NODE NAME
    less    58147 ddavison  cwd    DIR                1,5     3904              341671 /Users/ddavison
    less    58147 ddavison  txt    REG                1,5   278512            17652894 /Users/ddavison/tmp/3p/less/less
    less    58147 ddavison  txt    REG                1,5  2177216 1152921500312782999 /usr/lib/dyld
    less    58147 ddavison    0   PIPE 0x5823e9b12474b719    16384
    less    58147 ddavison    1u   CHR               16,0 0t191568                2079 /dev/ttys000
    less    58147 ddavison    2u   CHR               16,0 0t191568                2079 /dev/ttys000
    less    58147 ddavison    3r   CHR               16,0      0t0                2079 /dev/ttys000
    
  10. dandavison commented on Sep 10, 2022

    @dandavison
    Contributor

    Piping into fzf appears to trigger a similar bug as piping into less, e.g.

    ^yes | ^head -n 999 | ^fzf
    

    hangs on my Mac, and also similar problems have been reported piping content into fzf on ArchLinux (#6534) and in #6516 (OS TBD).

    (On a Mac I can reproduce the same less problem by piping into git, bat, and delta, which is expected since all those programs invoke less as their pager.)

    I've confirmed that the less and fzf problems are fixed on my MacOS machine by reverting 1d18f69.

  11. sophiajt commented on Sep 11, 2022

    @sophiajt
    Contributor

    Fixed with #6542

  12. added this to the v0.69 milestone on Sep 11, 2022
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

    A:external-commandscategory:bugdeprecated:platform-specificstatus:investigate

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions