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

IO.popen doesn't wait until a process ends but returns immediately #911

Closed
headius opened this issue Jul 25, 2013 · 1 comment
Closed

IO.popen doesn't wait until a process ends but returns immediately #911

headius opened this issue Jul 25, 2013 · 1 comment
Milestone

Comments

@headius
Copy link
Member

headius commented Jul 25, 2013

NOTE: Originally filed as http://jira.codehaus.org/browse/JRUBY-6162

Hi,

I hope that I'm wrong, but at the moment this looks like a serious bug to me, but maybe I just didn't do enough RTFM. I found this bug when using ActionMailer with sendmail. The "/usr/sbin/sendmail" process was only sometimes called and sometimes it wasn't (most often it wasn't but around every tenth time it suddenly worked)

I investigated it deeply and after hours I distilled it down to the following:

hk@hk:~$ rvm use jruby ruby -e "cmd='/bin/bash -c \"sleep 5\"'; puts Time.now ; system(cmd); puts Time.now; IO.popen(cmd) {} ; puts Time.now "
Wed Oct 26 16:37:08 +0200 2011
Wed Oct 26 16:37:13 +0200 2011
Wed Oct 26 16:37:13 +0200 2011
hk@hk:~$ rvm use 1.8.7 ruby -e "cmd='/bin/bash -c \"sleep 5\"'; puts Time.now ; system(cmd); puts Time.now; IO.popen(cmd) {} ; puts Time.now "
Wed Oct 26 16:37:18 +0200 2011
Wed Oct 26 16:37:23 +0200 2011
Wed Oct 26 16:37:28 +0200 2011
hk@hk:~$ 

As one can see, the system call on both Ruby Interpreters waits until the subprocess exits. But with MRI it also stops when using IO.popen, but not with JRuby. Here it returns immediately.

I found a very ugly workaround for the moment by doing something like the following:

module ActionMailer
  class Base
    def perform_delivery_sendmail(mail)
      sendmail_args = sendmail_settings[:arguments]
      sendmail_args += " -f \"#{mail['return-path']}\"" if mail['return-path']

      IO.popen("#{sendmail_settings[:location]} #{sendmail_args}", "r+") do |f| #r+ geht, w+ geht nicht richtig, bzw. nur manchmal
        f.puts mail.encoded.gsub(/\r/, '')
        f.close_write
        sleep 1 # <---- added this line in order to give sendmail some time to process
      end
    end
  end
end
{noformat}

Here are some environment infos:

{noformat}
hk@hk:~$ rvm info jruby

jruby-1.6.5:

  system:
    uname:       "Linux hk 3.0.0-12-generic #20-Ubuntu SMP Fri Oct 7 14:56:25 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux"
    bash:        "/bin/bash => GNU bash, Version 4.2.10(1)-release (x86_64-pc-linux-gnu)"
    zsh:         " => not installed"

  rvm:
    version:      "rvm 1.9.0 by Wayne E. Seguin (wayneeseguin@gmail.com) [https://rvm.beginrescueend.com/]"

  ruby:
    interpreter:  "jruby"
    version:      "1.6.5"
    date:         "2011-10-25"
    platform:     "linux-amd64-java"
    patchlevel:   "OpenJDK 64-Bit Server VM 1.6.0_23"
    full_version: "jruby 1.6.5 (ruby-1.8.7-p330) (2011-10-25 9dcd388) (OpenJDK 64-Bit Server VM 1.6.0_23) [linux-amd64-java]"

  homes:
    gem:          "/home/hk/.rvm/gems/jruby-1.6.5"
    ruby:         "/home/hk/.rvm/rubies/jruby-1.6.5"

  binaries:
    ruby:         "/home/hk/.rvm/rubies/jruby-1.6.5/bin/ruby"
    irb:          "/home/hk/.rvm/rubies/jruby-1.6.5/bin/irb"
    gem:          "/home/hk/.rvm/rubies/jruby-1.6.5/bin/gem"
    rake:         "/home/hk/.rvm/gems/jruby-1.6.5/bin/rake"

  environment:
    PATH:         "/home/hk/.rvm/gems/jruby-1.6.5/bin:/home/hk/.rvm/gems/jruby-1.6.5@global/bin:/home/hk/.rvm/rubies/jruby-1.6.5/bin:/home/hk/.rvm/bin:<other stuff>"
    GEM_HOME:     "/home/hk/.rvm/gems/jruby-1.6.5"
    GEM_PATH:     "/home/hk/.rvm/gems/jruby-1.6.5:/home/hk/.rvm/gems/jruby-1.6.5@global"
    MY_RUBY_HOME: "/home/hk/.rvm/rubies/jruby-1.6.5"
    IRBRC:        "/home/hk/.rvm/rubies/jruby-1.6.5/.irbrc"
    RUBYOPT:      ""
    gemset:       ""


hk@hk:~$ 

hk@hk:~$ rvm info 1.8.7

ruby-1.8.7-p352:

  system:
    uname:       "Linux hk 3.0.0-12-generic #20-Ubuntu SMP Fri Oct 7 14:56:25 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux"
    bash:        "/bin/bash => GNU bash, Version 4.2.10(1)-release (x86_64-pc-linux-gnu)"
    zsh:         " => not installed"

  rvm:
    version:      "rvm 1.9.0 by Wayne E. Seguin (wayneeseguin@gmail.com) [https://rvm.beginrescueend.com/]"

  ruby:
    interpreter:  "ruby"
    version:      "1.8.7"
    date:         "2011-06-30"
    platform:     "x86_64-linux"
    patchlevel:   "2011-06-30 patchlevel 352"
    full_version: "ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]"

  homes:
    gem:          "/home/hk/.rvm/gems/ruby-1.8.7-p352"
    ruby:         "/home/hk/.rvm/rubies/ruby-1.8.7-p352"

  binaries:
    ruby:         "/home/hk/.rvm/rubies/ruby-1.8.7-p352/bin/ruby"
    irb:          "/home/hk/.rvm/rubies/ruby-1.8.7-p352/bin/irb"
    gem:          "/home/hk/.rvm/rubies/ruby-1.8.7-p352/bin/gem"
    rake:         "/home/hk/.rvm/gems/ruby-1.8.7-p352/bin/rake"

  environment:
    PATH:         "/home/hk/.rvm/gems/ruby-1.8.7-p352/bin:/home/hk/.rvm/gems/ruby-1.8.7-p352@global/bin:/home/hk/.rvm/rubies/ruby-1.8.7-p352/bin:<other stuff>"
    GEM_HOME:     "/home/hk/.rvm/gems/ruby-1.8.7-p352"
    GEM_PATH:     "/home/hk/.rvm/gems/ruby-1.8.7-p352:/home/hk/.rvm/gems/ruby-1.8.7-p352@global"
    MY_RUBY_HOME: "/home/hk/.rvm/rubies/ruby-1.8.7-p352"
    IRBRC:        "/home/hk/.rvm/rubies/ruby-1.8.7-p352/.irbrc"
    RUBYOPT:      ""
    gemset:       ""


hk@hk:~$ 
@headius headius added this to the JRuby 9.0.0.0 milestone May 11, 2016
@headius
Copy link
Member Author

headius commented May 11, 2016

popen was reimplemented in 9k to use real native process managed. This issue is no longer a problem.

@headius headius closed this as completed May 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant