chruby
chruby copied to clipboard
Running chruby-exec from ruby hangs the shell
For example if you run ruby -e "puts chruby-exec ruby-2.0.0 -- ruby --version" you can see it spawning a shell which uses 100% CPU.
I don't know if rewriting chruby-exec into a function (https://github.com/postmodern/chruby/issues/127) would solve this issue.
Running this gives me:
-e:1: no .floating literal anymore; put 0 before dot puts ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux] ^ -e:1: syntax error, unexpected tINTEGER, expecting '(' puts ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux] ^
Replacing the " " with ' ' seems to fix this. Cannot reproduce either way.
Executing it in irb quits my irb session:
irb(main):001:0> `chruby-exec ruby-2.0.0 -- ruby --version`
=> "\e]7;file://Kif/Users/jeroen/Development/ruby/sock\aruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.1]\n"
[6] + 81045 suspended (tty output) irb
That was using zsh. I also tried it using a clean bash (nothing in .profile, ...):
irb(main):001:0> `chruby-exec ruby-2.0.0 -- ruby --version`
=> "\e]7;file://Kif/Users/jeroen\aruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.1]\n"
irb(main):002:0>
[1]+ Stopped irb
Executing ruby -e "puts chruby-exec ruby-2.0.0 -- ruby --version" in bash just quits the ruby process (instead of using 100% cpu like in zsh):
Kif:~ jeroen$ ruby -e "puts `chruby-exec ruby-2.0.0 -- ruby --version`"
-e:1: Invalid char `\033' in expression
-e:1: syntax error, unexpected ']', expecting $end
puts ruby...
^
Using ruby -e 'puts chruby-exec ruby-2.0.0 -- ruby --version' in bash works as expected.
To be honnest I have no idea on how I could debug this.
Executing it in irb (2.0.0p247):
`chruby-exec ruby-2.0.0 -- ruby --version`
=> "ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]\n"
`chruby-exec ruby-1.9 -- ruby --version`
=> "ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux]\n"
Okay, that is strange. Do you use zsh, bash or something else?
I'll see if I can track down what's acting up.
- bash 4.2.45
- ruby 2.0.0p247
- irb 0.7.0
Also, I executed irb via \irb to avoid any aliases. Do you use ohmyzsh by chance?
Yes, I use ohmyzsh. Would that cause problems? It shouln't when using bash (I changd my default shell in Terminall.app to bash to test).
Try running your examples without ohmyzsh loaded. It could be an alias it sets to hijack irb; also check alias output.
Kif:sock jeroen$ bash --version
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12)
Copyright (C) 2007 Free Software Foundation, Inc.
Kif:sock jeroen$ ruby --version
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
Kif:sock jeroen$ \irb --version
irb 0.9.5(05/04/13)
Kif:sock jeroen$ \irb
irb(main):001:0> `chruby-exec ruby-2.0.0 -- ruby --version`
=> "\e]7;file://Kif/Users/jeroen/Development/ruby/sock\aruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.1]\n"
irb(main):002:0>
[1]+ Stopped \irb
Kif:sock jeroen$ \irb
irb(main):001:0> `chruby-exec ruby-1.9.3 -- ruby --version`
=> "\e]7;file://Kif/Users/jeroen/Development/ruby/sock\aruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-darwin12.4.1]\n"
irb(main):002:0>
[2]+ Stopped \irb
Kif:sock jeroen$ \irb
irb(main):001:0> `chruby-exec ruby-1.8.7 -- ruby --version`
=> "\e]7;file://Kif/Users/jeroen/Development/ruby/sock\aruby 1.8.7 (2013-06-27 patchlevel 374) [i686-darwin12.4.1]\n"
irb(main):002:0>
[3]+ Stopped \irb
The bove output is with the system bash, ruby and irb on OSX 10.8. Nothing is loaded there besides any default OSX stuff (if there is such).
In my ohmyzsh config irb is not aliased.
Is this issue fixed? however I still have the same problem
irb(main):001:0> `chruby-exec ruby-2.1.2 -- bundle install`
=> "Using rake 10.3.2\nUsing i18n 0.6.11\nUsing multi_json 1.10.1\nUsing activesupport 3.2.19\nUsing builder 3.0.4\nUsing activemodel 3.2.19\nUsing erubis 2.7.0\nUsing journey 1.0.4\nUsing rack 1.4.5\nUsing rack-cache 1.2\nUsing rack-test 0.6.2\nUsing hike 1.2.3\nUsing tilt 1.4.1\nUsing sprockets 2.2.2\nUsing actionpack 3.2.19\nUsing mime-types 1.25.1\nUsing polyglot 0.3.5\nUsing treetop 1.4.15\nUsing mail 2.5.4\nUsing actionmailer 3.2.19\nUsing arel 3.0.3\nUsing tzinfo 0.3.41\nUsing activerecord 3.2.19\nUsing activeresource 3.2.19\nUsing json 1.8.1\nUsing rack-ssl 1.3.4\nUsing bundler 1.6.5\nUsing rdoc 3.12.2\nUsing thor 0.19.1\nUsing railties 3.2.19\nUsing rails 3.2.19\nYour bundle is complete!\nUse `bundle show [gemname]` to see where a bundled gem is installed.\n"
[6] + 10468 suspended (tty output) bundled_irb
This appears to still happen, but only with zsh and within irb.
Experiencing a similar issue with chruby-exec and zsh outside of irb. The symptom is the spawned shell command process just hangs and doesn't actually fork the ruby. Only on zsh, bash doesn't have this issue.
($SHELL -l -i -c 'id' works)
Here's the trouble I've found. It occurs with this Rakefile snippet (in a tiny chruby PR that allows setting RUBIES in ruby-exec)
sh "RB=($RUBIES_ROOT/*); RB=\"RUBIES=(${RB[@]})\"; chruby-exec \"$RB\" ruby-2.2.0 -- gem build #{@gemspec_file}"
sh "RB=($RUBIES_ROOT/*); RB=\"RUBIES=(${RB[@]})\"; chruby-exec \"$RB\" jruby -- gem build #{@gemspec_file}"
The first one runs fine, the second one hangs.
Q1: Is this some weird zsh history/cache/zcomp thing? Q2: Is this the same or a related issue?
I've tried empty .zshrc, .zprofile, .zlogin, .zlogout, and
.zshenv = export RUBIES_ROOT='/usr/local/ruby' # for this rake example
The root cause appears to be multiple invocations of zsh interactive -i login shells and logouts, which does something weird to the tty, and so breaks subsequent invocations of chruby-exec. The most sensible fix seems to be removing [[ -t 0 ]] && shell_opts+=("-i"). I've encountered another anomaly with bash as well when running the -i commands via a generated mktemp #!$SHELL ${shell_opts[@]} script instead of as a command.
Moral of the story: don't get too cute with spawning $SHELL, or s/he will bite back.
I'm also (still) having this issue. Is there anything I could do to help get it fixed? I notice @steakknife appears to have a fix
I got the same issue, when doing this in Zsh:
$ ruby -e '2.times { system("chruby-exec 2.4.1 -- ruby -v") }'
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
zsh: suspended (tty input) ruby -e '2.times { system("chruby-exec 2.4.1 -- ruby -v") }'
So the terminal is suspended and fg resumes it.
Removing the extra -i argument to the shell solves it.
@postmodern Could we commit that fix? Is -i needed for other shells? At least on Zsh it seems to hurt more than it helps.
This bug occurs on bash, too.
Script to reproduce this bug
#!/bin/bash
. /usr/local/share/chruby/chruby.sh
for i in {1,2}; do
echo "$i"
chruby-exec 2.6.3 -- ruby --version
done
Then the script stops at second chruby.
$ bash test.sh
#1
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
#2
[1]+ Stopped bash test.sh
$ fg
bash test.sh
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
@postmodern What do you think of this? Should -i not be passed?
I can also confirm this bug when in Bash, using wwtd which shells out to chruby-exec.
And also with the IRB examples mentioned above:
$ irb
> `chruby-exec 2.6 -- ruby -v`
"ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux]\n"
[1]+ Stopped irb
I was also seeing this issue with last released version.
No longer happening if I use chruby from master instead of 0.3.9.
I guess can be fixed if there's a new release: https://github.com/postmodern/chruby/issues/383?
No longer happening if I use
chrubyfrom master instead of0.3.9.
For those using Homebrew, you can install chruby from the master branch using brew install chruby --HEAD.