Skip to content

setpgid fails in fish shell #1210

Closed
Closed

Description

In fish 2.0.0 and newer, piping find / -maxdepth 0 to any other command, e.g. head, returns an error.

Expected:

sviatoslav@7 ~> find / -maxdepth 0 | head
/

Got:

sviatoslav@7 ~> find / -maxdepth 0 | head
Could not send process 17, 'head' in job 1, 'find / -maxdepth 0 | head' from group 2 to group 16
setpgid: Operation not permitted
head: error reading ‘standard input’: Input/output error

My Windows build number is 14393.321

To install fish, run sudo apt install fish

Activity

  1. stehufntdev commented on Oct 17, 2016

    @stehufntdev

    Thanks for reporting the issue. Can you please collect a strace with follow forks of the failing command?

  2. Perlence commented on Oct 17, 2016

    @Perlence
    Author

    Well, as odd as it is, the command works when invoked like this:

    sviatoslav@7 ~> fish -c "find / -maxdepth 0 | head"
    /
    sviatoslav@7 ~> echo "find / -maxdepth 0 | head" | fish
    /
    

    I thought I would run strace -f -o fish.log fish -c "find / -maxdepth 0 | head", but it works that way 🤔

  3. Perlence commented on Oct 17, 2016

    @Perlence
    Author

    Actually, it's more general, than I thought:

    sviatoslav@7 ~> echo > blank
    sviatoslav@7 ~> cat blank | head
    Could not send process 212, 'head' in job 1, 'cat blank | head' from group 2 to group 211
    setpgid: Operation not permitted
    head: error reading ‘standard input’: Input/output error
    
  4. Perlence commented on Oct 17, 2016

    @Perlence
    Author

    Ok, I couldn't reproduce the error in follow forks mode, so here's strace attached to a fish interactive session right before executing cat blank | head.

  5. stehufntdev commented on Oct 19, 2016

    @stehufntdev

    Thanks for providing the strace, but there's not much information we can get without follow forks since the error is happening in the child process. I double checked the strace and confirmed. We'll have to try and get a local repro for debugging.

  6. aandreev commented on Oct 28, 2016

    @aandreev

    I am having a similar issue on build 14955:

    ~ λ> touch mouse
    
    ~ λ> cat mouse | sort | uniq | wc -l
    Could not send process 257, 'sort' in job 1, 'cat mouse | sort | uniq | wc -l' from group 15 to group 256
    setpgid: Operation not permitted
    sort: read failed: -: Input/output error
    Could not send process 258, 'uniq' in job 1, 'cat mouse | sort | uniq | wc -l' from group 15 to group 256
    setpgid: Operation not permitted
    uniq: error reading '-'
    Could not send process 259, 'wc' in job 1, 'cat mouse | sort | uniq | wc -l' from group 15 to group 256
    setpgid: Operation not permitted
    wc: 'standard input': Input/output error
    0
    
    ~ λ> id
    uid=1000(andrey) gid=1000(andrey) groups=1000(andrey),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev)
    
    ~ λ> sudo cat mouse | sort | uniq | wc -l
    [sudo] password for andrey:
    0
    
    ~ λ> ll mouse
    -rw-rw-rw- 1 andrey andrey 0 Oct 28 14:21 mouse
    
    ~ λ> fish -c "cat mouse | sort | uniq | wc -l"
    0
    
    ~ λ> pstree
    init─┬─bash───tmux
         └─tmux───fish───pstree
    
  7. aandreev commented on Oct 28, 2016

    @aandreev

    Strangely enough, if i continue with:

    ~ λ> strace -o fishdump -ff fish
    Welcome to fish, the friendly interactive shell
    Type help for instructions on how to use fish
    
    ~ λ> cat mouse | sort | uniq | wc -l
    0
    
    ~ λ> pstree
    init─┬─bash───tmux
         └─tmux───fish───strace───fish───pstree
    

    it works?!?!

  8. Perlence commented on Oct 28, 2016

    @Perlence
    Author

    aandreev Yep, I was puzzled by this too 😄

  9. aandreev commented on Oct 28, 2016

    @aandreev

    Looks to me like a race condition. I occasionally get it to run, and always under strace.

    Welcome to fish, the friendly interactive shell                                                                                                                                                                                                                                                           [6/6]Type help for instructions on how to use fish
    
    ~ λ> cat mouse | sort | uniq | wc -l
    0
    
    ~ λ> cat mouse | sort | uniq | wc -l
    Could not send process 59, 'sort' in job 1, 'cat mouse | sort | uniq | wc -l' from group 15 to group 58
    setpgid: Operation not permitted
    sort: read failed: -: Input/output error
    Could not send process 60, 'uniq' in job 1, 'cat mouse | sort | uniq | wc -l' from group 15 to group 58
    setpgid: Operation not permitted
    uniq: error reading '-'
    Could not send process 61, 'wc' in job 1, 'cat mouse | sort | uniq | wc -l' from group 15 to group 58
    setpgid: Operation not permitted
    wc: 'standard input': Input/output error
    0
    
  10. aandreev commented on Oct 28, 2016

    @aandreev

    Confirming it is a timing issue. If I load the CPU by

     bash -c 'fulload() { dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null & }; fulload; read; killall dd'
    

    I am getting the cat pipe to run almost always successfully, with rare errors.

  11. saschagehlich commented on Nov 24, 2016

    @saschagehlich

    aandreev Is this something that needs to be fixed by MS or by the fish people?

  12. mqudsi commented on Apr 6, 2017

    @mqudsi

    I'm pretty sure this is a WSL bug that could be worked around in fish, but the right fix would have to come from MSFT? Please correct me if I'm wrong, though!

  13. gglanzani commented on Apr 18, 2017

    @gglanzani

    I'm getting hit by this pretty hard as well since the latest release. Probably WSL is now more efficient, so I hit the race condition more often :P

  14. 6 remaining items

  15. benhillis commented on Aug 15, 2017

    @benhillis
    Member

    I believe this was fixed in 16251. Please let me know if you're still experiencing issues.

  16. mqudsi commented on Aug 15, 2017

    @mqudsi

    Ben Hillis (@benhillis) so I tracked down this bug on the fish side of things and the only idiosyncrasy I could find in WSL was that sometimes immediately after a new process group is created, EPERM is returned when another tries to join this group (via tcsetpgrp) but upon retry, the operation succeeds. Could you possibly expound on the fix for this to see if it matches our experience? In the meantime, fish 3.0 pre release builds work around the issue.

  17. benhillis commented on Aug 15, 2017

    @benhillis
    Member

    Didn't mean to close this, buttons are too close together. There were some tty related bugfixes in the build I linked that I believe will have resolved this. Mahmoud Al-Qudsi (@mqudsi) - Are you still able to reproduce this issue?

  18. mqudsi commented on Aug 15, 2017

    @mqudsi

    Ben Hillis (@benhillis) I'm on 15063 because my pasts experience with beta builds taught me that symbols are almost never available, which made getting useful info out of BSODs impossible. So I can't comment on whether it's fixed in 16251. My commits to Fish should avoid the issue from appearing to the end user entirely in all cases if they're running an up-to-date build, but that shouldn't be taken as an issue that the tcsetpgrp matter was resolved, naturally.

  19. mqudsi commented on Aug 15, 2017

    @mqudsi

    Ben Hillis (@benhillis) sorry, I somehow didn't catch what you said about tty. The problem we ran into seemed to affect both foreground and background process with and without terminal input/output equally; I don't think that would take care of it. It was almost as if tcsetpgrp was querying an out-of-date snapshot of process groups instead of the latest.

  20. arooni commented on Mar 3, 2018

    @arooni

    Would this error (trying to use fish shell 2.7.1 + ubuntu 16.04 + fisher + fzf plugin) be related to this bug?

    v/w/m/wp-content  Could not send process 23992, '__fzfcmd' in job 2, 'history | __fzfcmd +s +m --tiebreak=index --toggle-sort=ctrl-r ' from group 30993 to group 23717
    setpgid: Operation not permitted
    Could not send job 2 ('history | __fzfcmd +s +m --tiebreak=index --toggle-sort=ctrl-r ') to foreground
    tcsetpgrp: No such process
    ls
    fish: Could not send job 2 (“history | __fzfcmd +s +m --tiebreak=index --toggle-sort=ctrl-r | read -l select”) to foreground
    tcsetpgrp: No such process

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions