Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing stdout using Open3.popen after Dir.chdir #3655

Open
hsbt opened this issue Feb 9, 2016 · 6 comments
Open

Missing stdout using Open3.popen after Dir.chdir #3655

hsbt opened this issue Feb 9, 2016 · 6 comments

Comments

@hsbt
Copy link

hsbt commented Feb 9, 2016

It's related with #3653 probably. I found another issue.

I invoke following code named inlineruby.rb.

require 'open3'

RUBY = ENV['RUBY'] || File.join(
  RbConfig::CONFIG['bindir'],
  RbConfig::CONFIG['ruby_install_name'] + RbConfig::CONFIG['EXEEXT'])

def run_ruby(*option_list)
  Open3.popen3(RUBY, *option_list) {|inn, out, err, wait|
    inn.close

    @exit = wait ? wait.value : $?
    @out = out.read
    @err = err.read
  }
  p [@exit, @out, @err]
end


run_ruby '-e', 'puts ["a"].size'

Dir.chdir 'test' # prepare to create test dir.
run_ruby '-e', 'puts ["a"].size'

I got following results with JRuby 9.0.5.0

% ruby -v inlineruby.rb
jruby 9.0.5.0 (2.2.3) 2016-01-26 7bee00d Java HotSpot(TM) 64-Bit Server VM 25.72-b15 on 1.8.0_72-b15 +jit [darwin-x86_64]
[#<Process::Status: pid 50198 exit 0>, "1\n", ""]
[#<Process::Status: pid 50199 exit 0>, "\n", ""]

JRuby 1.7.24 returns same results.

jruby 1.7.24 (1.9.3p551) 2016-01-20 bd68d85 on Java HotSpot(TM) 64-Bit Server VM 1.8.0_72-b15 +jit [darwin-x86_64]
[#<Process::Status: pid=50468,exited(0)>, "1\n", ""]
[#<Process::Status: pid=50470,exited(0)>, "1\n", ""]

Is it intentional changes?

@enebo enebo added this to the JRuby 9.1.0.0 milestone Feb 9, 2016
@enebo enebo added the core label Feb 9, 2016
@enebo
Copy link
Member

enebo commented Feb 9, 2016

@hsbt our IO subsystem and to some exent our process-oriented code was completely changed since 1.7.x so this is still just breakage from those changes.

@hsbt
Copy link
Author

hsbt commented Feb 10, 2016

I understand it.

but CRuby returns same results as JRuby 1.7.x

% ruby -v inlineruby.rb
ruby 2.4.0dev (2016-02-10 trunk 53797) [x86_64-darwin15]
[#<Process::Status: pid 21864 exit 0>, "1\n", ""]
[#<Process::Status: pid 21865 exit 0>, "1\n", ""]

I think this Dir.chdir behavior is inconsistency.

/cc @headius

@headius
Copy link
Member

headius commented Apr 20, 2016

This is the same issue as #3653 but for a different method. Open3.popen3 eventually uses spawn which has issues with chdir, expanding such spawns to a shell invocation. In #3653 I made a partial fix to the related system logic, but the eventual fix is still a problem. We can't actually chdir the process when you Dir.chdir because it could have serious side effects for the currently-running JVM. We can't quickly do it before spawning because it would race with other subprocess invocations that have their own chdirs. And we can't properly fork + chdir + exec without having a specialized piece of native code for that (similar to what the JVM has for its process launching.

In any case there's nothing going to get fixed for this in 9.1. I'll update some tags and punt.

@headius
Copy link
Member

headius commented Apr 20, 2016

Note that this affects Windows even though it runs the old logic, but it may be better masked by hacks in our non-native Process logic. We may be able to duplicate those hacks, but I'm not sure we can completely eliminate the additional cases where we shell-launch.

@headius headius modified the milestones: JRuby 9.1.1.0, JRuby 9.1.0.0 Apr 20, 2016
@headius headius modified the milestones: JRuby 9.1.1.0, JRuby 9.1.2.0 May 11, 2016
@enebo enebo modified the milestones: JRuby 9.1.2.0, JRuby 9.1.3.0 May 23, 2016
@headius
Copy link
Member

headius commented Aug 23, 2016

Definitely nothing more going to happen on this one before 9.1.3.0. I think we should punt to 9.2 and try to get Windows native process support in along with Ruby 2.4 features.

@headius
Copy link
Member

headius commented May 15, 2018

Link with #5145, #985 and detarget.

@headius headius removed this from the JRuby 9.2.0.0 milestone May 15, 2018
@byteit101 byteit101 self-assigned this Jan 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants