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

Too big for int #4744

Closed
stergiom opened this issue Aug 18, 2017 · 3 comments
Closed

Too big for int #4744

stergiom opened this issue Aug 18, 2017 · 3 comments

Comments

@stergiom
Copy link

Environment

  • jruby 9.1.12.0 (2.3.3) 2017-06-15 33c6439 Java HotSpot(TM) 64-Bit Server VM 25.144-b01 on 1.8.0_144-b01 +jit [darwin-x86_64]

  • When using httpclient and supplying a high timeout value it breaks with:

RangeError: too big for int: 100000000000
.. /jruby-9.1.12.0/gems/httpclient-2.8.3/lib/httpclient/jruby_ssl_socket.rb:26:in `connect'

Expected Behavior

< headius> if someone requests a timeout larger than 64-bit long might as well wait forever

@headius
Copy link
Member

headius commented Aug 18, 2017

If you can provide a simple reproduction script, that would be helpful. I think I know where the issue is, though.

You can also help us by passing -Xbacktrace.style=full to get the full JVM stack trace, which will tell us precisely where the error is happening.

I'm poking at it now.

@headius
Copy link
Member

headius commented Aug 18, 2017

Ok, so it looks like this is a bug in httpclient or, arguably, the library that's providing that large timeout value.

httpclient apparently implements its own SSL socket for JRuby by calling into the Java socket and SSL APIs directly. The call to @socket.connect with an address and a timeout is actually calling java.net.Socket.connect, and the error indicates that the timeout being passed in is too large to convert into connect's 32-bit signed int timeout.

Unfortunately, there doesn't appear to be anything we can do in JRuby. The only method that matches does require int, and the value being passed is too big. I'll look into improving the error message, but I recommend you reopen this with httpclient (they probably should intercept too-large values and truncate or report a good error rather than an obscure error like this).

@headius headius closed this as completed Aug 18, 2017
@headius headius added this to the Invalid or Duplicate milestone Aug 18, 2017
@headius
Copy link
Member

headius commented Aug 18, 2017

Here's output from a similar case. Blah.blah is a Java method that receives and returns int.

[] ~/projects/jruby $ jruby -e 'Java::Blah.blah(10000000000000000000000000000000)'
RangeError: bignum too big to convert into `long'
  <main> at -e:1

The following output is the full trace, showing that this error stems from big2long logic used when preparing the arguments for the Java call. The Bignum is too large for int, so a RangeError is raised.

[] ~/projects/jruby $ jruby -Xbacktrace.style=full -e 'Java::Blah.blah(10000000000000000000000000000000)'
RangeError: bignum too big to convert into `long'
        getStackTrace at java/lang/Thread.java:1559
     getBacktraceData at org/jruby/runtime/backtrace/TraceType.java:246
         getBacktrace at org/jruby/runtime/backtrace/TraceType.java:47
     prepareBacktrace at org/jruby/RubyException.java:235
             preRaise at org/jruby/exceptions/RaiseException.java:216
             preRaise at org/jruby/exceptions/RaiseException.java:183
               <init> at org/jruby/exceptions/RaiseException.java:111
    newRaiseException at org/jruby/Ruby.java:4137
        newRangeError at org/jruby/Ruby.java:3832
             big2long at org/jruby/RubyBignum.java:164
         getLongValue at org/jruby/RubyBignum.java:116
               coerce at org/jruby/javasupport/JavaUtil.java:936
               toJava at org/jruby/RubyNumeric.java:1278
                 call at org/jruby/java/invokers/StaticMethodInvoker.java:49
         cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:338
                 call at org/jruby/runtime/callsite/CachingCallSite.java:163
    invokeOther0:blah at -e:1
               <main> at -e:1
  invokeWithArguments at java/lang/invoke/MethodHandle.java:627
                 load at org/jruby/ir/Compiler.java:95
            runScript at org/jruby/Ruby.java:827
          runNormally at org/jruby/Ruby.java:746
          runNormally at org/jruby/Ruby.java:764
          runFromMain at org/jruby/Ruby.java:577
        doRunFromMain at org/jruby/Main.java:417
          internalRun at org/jruby/Main.java:305
                  run at org/jruby/Main.java:232
                 main at org/jruby/Main.java:204

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

2 participants