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.select does not properly coerce timeout argument #821

Closed
headius opened this issue Jun 23, 2013 · 6 comments
Closed

IO.select does not properly coerce timeout argument #821

headius opened this issue Jun 23, 2013 · 6 comments

Comments

@headius
Copy link
Member

@headius headius commented Jun 23, 2013

Given this code:

class Foo
  def initialize
    @a = 1
  end

  def method_missing(m, *args)
    @a.send(m, *args)
  end
end

IO.select([], [], [], Foo.new)

MRI 1.9.3 and 2.0.0 work fine, while JRuby (all modes) and MRI 1.8.7 raise "can't convert Foo into time interval (TypeError)". We are missing coercion logic.

@headius
Copy link
Member Author

@headius headius commented Jun 23, 2013

If someone else wants to take this, go ahead. I'm probably not going to get to it tonight.

@sfgeorge
Copy link

@sfgeorge sfgeorge commented Aug 30, 2013

FYI, I'm finding that this issue transcends more than just IO.select. Another example:

require 'active_support/core_ext/numeric/time'
sleep 1 # Works
sleep 1.second # Fails with:

# TypeError: can't convert ActiveSupport::Durationinto time interval
#   from org/jruby/RubyKernel.java:798:in `sleep'
#   from (irb):3:in `evaluate'
#   from org/jruby/RubyKernel.java:1093:in `eval'
#   from org/jruby/RubyKernel.java:1489:in `loop'
#   from org/jruby/RubyKernel.java:1254:in `catch'
#   from org/jruby/RubyKernel.java:1254:in `catch'
#   from /Users/sgeorge/.rvm/rubies/jruby-1.7.4/bin/irb:13:in `(root)'

Versions
jruby: 1.7.4
activesupport: 3.2.12

@headius
Copy link
Member Author

@headius headius commented Aug 31, 2013

Please file additional issues for cases where we do not coerce properly (and ideally make sure it's still broken on JRuby master).

@bbozo
Copy link

@bbozo bbozo commented Nov 5, 2013

@headius

Got same problem with jruby 1.7.5 and ActiveSupport 4.0.0:

[54] pry(main)> sleep 1.minute
TypeError: can't convert ActiveSupport::Durationinto time interval
from org/jruby/RubyKernel.java:826:in `sleep'
[55] pry(main)> 1.minute.class
=> Fixnum

what additional data do you need to tackle this?

@iaddict
Copy link
Contributor

@iaddict iaddict commented Jun 26, 2014

The problem still shows on jruby 1.7.12 and ActiveSupport 4.1.0:

irb(main):013:0> ActiveSupport.version
=> #<Gem::Version "4.1.0">
irb(main):014:0> sleep 5.seconds
TypeError: can't convert ActiveSupport::Durationinto time interval
    from org/jruby/RubyKernel.java:809:in `sleep'
    from (irb):14:in `evaluate'
    from org/jruby/RubyKernel.java:1101:in `eval'
    from org/jruby/RubyKernel.java:1501:in `loop'
    from org/jruby/RubyKernel.java:1264:in `catch'
    from org/jruby/RubyKernel.java:1264:in `catch'
    from /Users/de95079/.rubies/jruby-1.7.12/bin/jirb:13:in `(root)'

@rtyler
Copy link

@rtyler rtyler commented Aug 2, 2015

I've done some followup testing and the activesupport use-case is fixed at least in JRuby 1.7.21 but the original IO#select reproduction case from @headius is still broken.

➜  ~  pry
[1] pry(main)> require 'active_support/core_ext/numeric/time'
=> true
[2] pry(main)> sleep 1
=> 1
[3] pry(main)> sleep 2.seconds
=> 2
[4] pry(main)> sleep 1.second
=> 1
[5] pry(main)> RUBY_VERSION
=> "1.9.3"
[6] pry(main)> RUBY_PLATFORM
=> "java"
[7] pry(main)> 
[7] pry(main)> class Foo
[7] pry(main)*   def initialize  
[7] pry(main)*     @a = 1    
[7] pry(main)*   end    
[7] pry(main)*   
[7] pry(main)*   def method_missing(m, *args)  
[7] pry(main)*     @a.send(m, *args)    
[7] pry(main)*   end    
[7] pry(main)* end  
=> nil
[8] pry(main)> 
[9] pry(main)> IO.select([], [], [], Foo.new)
TypeError: can't convert Foo into time interval
from org/jruby/RubyIO.java:3682:in `select'
[10] pry(main)> 
Using /home/tyler/.rvm/gems/jruby-9.0.0.0.pre1 with gemset rubygems
➜  ~  pry
[1] pry(main)> class Foo
[1] pry(main)*   def initialize  
[1] pry(main)*     @a = 1    
[1] pry(main)*   end    
[1] pry(main)*   
[1] pry(main)*   def method_missing(m, *args)  
[1] pry(main)*     @a.send(m, *args)    
[1] pry(main)*   end    
[1] pry(main)* end  
=> :method_missing
[2] pry(main)> 
[3] pry(main)> IO.select([], [], [], Foo.new)
TypeError: can't convert Foo into Float
from org/jruby/RubyIO.java:3330:in `select'
[4] pry(main)> 

kares added a commit that referenced this issue Jan 7, 2016
@kares kares added this to the JRuby 1.7.24 milestone Jan 7, 2016
kares added a commit that referenced this issue Jan 8, 2016
* jruby-1_7:
  convert IO.select timeout argument to_f when its an unknown type (closing #821)
  convert Bignum timeout argument in `IO.select` as well
  remove unused private method in RubyIO + make method call in constructor final
  [build] fix typo in pom.rb for jruby-dist
  improve fix for dist build
  Fix dist build final name, which broke dist CI.
kares added a commit that referenced this issue Jan 8, 2016
@kares kares closed this Jan 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants