You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Command substitution leaks processes if they expect input (command substitutions run in their own process group) #1362
Actual: $var contains an empty string, and if you run jobs, a stopped but not reaped cat process lingers unless you run kill -9 on it.
I understand that in this case, I could use read, but this error would still be a thing.
Reacted by Moved to @ad-si, Sylvain Bannier, Bjorn Neergaard, Marc, aeosynth, Łukasz Jan Niemier, Awal Garg, Manuel Mendez, Noah Frederick, Arne Döring and 8 more
In bash and zsh, command substitutions run in the process group of the shell. In fish, they run in their own process group. So when they try to read from stdin, they get SIGTTIN or whatever, and stop. Then fish notices they stopped and just continues on, allowing the command substitution to return.
So yes, as I already stated in the mailing list, I'm unable to use fzf in fish shell, and this makes fish completely out for me (fzf is SO useful)
ridiculousfish, from your message I would assume this behavior can't be changed by definition, like "it's feature, not bug". Am I right? Or, will it be fixed?
I'd also like to bump this issue. I'm seeing similar problems using the same program (fzf), but this also applies in general to any program that needs to accept input and output to stdout.
I would like to store the result of a mysql query with set result (mysql -uroot -p -e "...") but since the password is never requested, it does not work.
This is really a UI question - what ought fish to do if a command substitution stops without exiting?
@ridiculousfish: Honestly, the UI question comes later. The first thing we ought to do is remove the reason these things are stopping in the first place - because they got SIGTTOU, because we don't allow that they use the terminal. That's the most common reason for stopping, so if we remove that, 99% of use for that UI disappears.
Note also that currently echo (cat | string trim) will hang with no obvious way out because we wait on that forever.
I'll PR a possible fix for this now.
Reacted by Adam Porter, Amar Sood and Braham Snyder
I hit this issue again both yesterday and today. I didn't reread the thread, the last comment makes it look like this might be a known deficiency, but I reported it here as it seems like a regression. After some debugging, I was able to identify that the issue occurs when I pipe bash -i into a function. SS included to make it easier to read, source included to make it easier to reproduce.
# ===== Demo the issue =====# hangs (I'll press C-c)
$ bash -i -c 'echo hello >&2'| grep whatever
Job 3, '$ bash -i -c 'echo hello >&2' |…' has stopped
# works (use the command instead of the function)
$ bash -i -c 'echo hello >&2'|command grep whatever
hello
# works (remove the -i flag)
$ bash -c 'echo hello >&2'| grep whatever
hello
# ===== Other potentially useful info =====# the grep function
$ type grep
grep is a functionwith definition
functiongrepcommand grep --color=auto $argv
end
# the fish version
$ fish --version
fish, version 2.7.1
# this is as up-to-date as is installable
$ brew upgrade fish
Error: fish 2.7.1 already installed
Oh. One other maybe relevant thing: I pressed C-c, but it really stopped the process. ps shows a "T" (I assume this is SIGSTOP) both before and after I press C-c. After I fg, it prints "hello" and exits normally.
This kind of implies to me that it could be a different issue (b/c it resumes when I foreground it, but the the original had to be SIGKILLed, I believe). Let me know if you want me to post this as its own issue.
This kind of implies to me that it could be a different issue
Very much a different issue - this one is explicitly about command substitutions - echo (this stuff).
The problem with bash -i seems to be that it grabs the terminal for itself - strace -e ioctl shows it doing one with TIOCSPGRP - which is the underlying syscall for tcsetpgrp on linux.
Activity
ridiculousfish commentedon Mar 27, 2014
In bash and zsh, command substitutions run in the process group of the shell. In fish, they run in their own process group. So when they try to read from stdin, they get SIGTTIN or whatever, and stop. Then fish notices they stopped and just continues on, allowing the command substitution to return.
zanchey commentedon Mar 29, 2014
This has come up on the mailing list regarding fzf.
dimonomid commentedon Mar 29, 2014
zanchey, thanks for pointing me to this issue.
So yes, as I already stated in the mailing list, I'm unable to use fzf in fish shell, and this makes fish completely out for me (fzf is SO useful)
ridiculousfish, from your message I would assume this behavior can't be changed by definition, like "it's feature, not bug". Am I right? Or, will it be fixed?
neersighted commentedon Jun 23, 2014
I'd also like to bump this issue. I'm seeing similar problems using the same program (fzf), but this also applies in general to any program that needs to accept input and output to stdout.
/cc @junegunn
lilyball commentedon Sep 15, 2014
@ridiculousfish What is the reason behind command substitutions running in their own process group?
ByScripts commentedon Nov 17, 2014
Is there any workaround for this ?
I would like to store the result of a mysql query with
set result (mysql -uroot -p -e "...")but since the password is never requested, it does not work.zanchey commentedon Jan 16, 2015
fzfrecommends a workaround which may be helpful in some instances - see the fzf README for an example.paulcarey commentedon Jan 16, 2015
Rather than calling
$ vim (git ls-files | peco)which fails for the reason described above,xargscan be used to the same effect.I'd guess that the original issue with
setcould be worked around with a wrapper function that set a universal variable, but I haven't tried this.jcelliott commentedon Jan 27, 2015
Another vote for finding a way to fix this. Is it something that can reasonably be changed?
ridiculousfish commentedon Jan 27, 2015
Oh sure, we just have to fix it.
jcelliott commentedon Jan 28, 2015
Any pointers on where to start looking?
22 remaining items
faho commentedon Mar 29, 2017
@ridiculousfish: Honestly, the UI question comes later. The first thing we ought to do is remove the reason these things are stopping in the first place - because they got SIGTTOU, because we don't allow that they use the terminal. That's the most common reason for stopping, so if we remove that, 99% of use for that UI disappears.
Note also that currently
echo (cat | string trim)will hang with no obvious way out because we wait on that forever.I'll PR a possible fix for this now.
Also give subshells the terminal
Changelog #3922/#1362
Also give subshells the terminal
Changelog fish-shell#3922/fish-shell#1362
Fix suggested fish command to load variables
Fix suggested fish command to load variables
fish now works fine, so we don't need it anymore:
JoshCheek commentedon Apr 18, 2018
I hit this issue again both yesterday and today. I didn't reread the thread, the last comment makes it look like this might be a known deficiency, but I reported it here as it seems like a regression. After some debugging, I was able to identify that the issue occurs when I pipe
bash -iinto a function. SS included to make it easier to read, source included to make it easier to reproduce.JoshCheek commentedon Apr 18, 2018
Oh. One other maybe relevant thing: I pressed C-c, but it really stopped the process.
psshows a "T" (I assume this is SIGSTOP) both before and after I press C-c. After Ifg, it prints "hello" and exits normally.This kind of implies to me that it could be a different issue (b/c it resumes when I foreground it, but the the original had to be SIGKILLed, I believe). Let me know if you want me to post this as its own issue.
faho commentedon Apr 19, 2018
Very much a different issue - this one is explicitly about command substitutions -
echo (this stuff).The problem with
bash -iseems to be that it grabs the terminal for itself -strace -e ioctlshows it doing one with TIOCSPGRP - which is the underlying syscall fortcsetpgrpon linux.JoshCheek commentedon Apr 19, 2018
Okay, made a new issue for it here