Skip to content

Running chruby-exec from ruby hangs the shell #193

Open
jeroenj opened this Issue Aug 22, 2013 · 13 comments

5 participants

@jeroenj
jeroenj commented Aug 22, 2013

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 (#127) would solve this issue.

@postmodern
Owner

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.

@jeroenj
jeroenj commented Aug 23, 2013

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.

@postmodern
Owner

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"
@jeroenj
jeroenj commented Aug 23, 2013

Okay, that is strange. Do you use zsh, bash or something else?

I'll see if I can track down what's acting up.

@postmodern
Owner
  • 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?

@jeroenj
jeroenj commented Aug 23, 2013

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).

@postmodern
Owner

Try running your examples without ohmyzsh loaded. It could be an alias it sets to hijack irb; also check alias output.

@jeroenj
jeroenj commented Aug 23, 2013
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.

@havenwood havenwood added the exec label Sep 1, 2014
@ipmsteven

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
@postmodern
Owner

This appears to still happen, but only with zsh and within irb.

@steakknife

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)

@steakknife

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

@steakknife

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.

@steakknife steakknife added a commit to steakknife/chruby that referenced this issue Jan 27, 2015
@steakknife steakknife fixed and also fixes #193 c4e30d6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.