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

net-ldap#bind fails in jruby-9.1.0.0 (but works in jruby-9.0.5.0) #3863

Closed
gregclar opened this issue May 9, 2016 · 14 comments
Closed

net-ldap#bind fails in jruby-9.1.0.0 (but works in jruby-9.0.5.0) #3863

gregclar opened this issue May 9, 2016 · 14 comments

Comments

@gregclar
Copy link

gregclar commented May 9, 2016

Environment

$ jruby -v
jruby 9.1.0.0 (2.3.0) 2016-05-02 a633c63 Java HotSpot(TM) 64-Bit Server VM 23.21-b01 on 1.7.0_21-b12 +jit [darwin-x86_64]

$ gem list --local

*** LOCAL GEMS ***

bundler (1.12.3)
jar-dependencies (default: 0.3.2)
jruby-openssl (0.9.15 java)
json (1.8.3 java)
minitest (default: 5.4.1)
net-ldap (0.14.0)
net-telnet (default: 0.1.1)
power_assert (default: 0.2.3)
psych (2.0.17 java)
racc (1.4.13 java)
rake (default: 10.4.2)
rdoc (default: 4.2.0)
test-unit (default: 3.1.1)

$ uname -a
Darwin IBISs-iMac.local 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64

Expected Behavior

This is how it works under jruby-9.0.5.0:

 IBISs-iMac Mon May 09 16:24:16  gregc  [jruby-9.0.5.0 (set by /Users/gregc/.rbenv/version)]  ~
$ irb
Configured by ~/.irbrc
irb(main):001:0> require 'net-ldap'
=> true
irb(main):002:0> ldap = Net::LDAP.new
=> #<Net::LDAP:0x7e7eb4f6 @connect_timeout=nil, @force_no_page=false, @host="127.0.0.1", @hosts=nil, @auth={:method=>:anonymous}, @encryption=nil, @base="dc=com", @port=389, @open_connection=nil, @verbose=false, @instrumentation_service=nil>
irb(main):003:0> ldap.host = 'localhost'
=> "localhost"
irb(main):004:0> ldap.port = 10389
=> 10389
irb(main):005:0> ldap.auth "uid=admin,ou=system", "secret"
=> {:method=>:simple, :username=>"uid=admin,ou=system", :password=>"secret"}
irb(main):006:0> ldap.bind
=> true

I have many gems installed under 9.0.5.0, so haven't listed them here. For 9.1.0.0 actual (below) I installed 9.1.0.0 clean and added the minimal gems to replicate the problem.

Commands I used in irb are:

require 'net-ldap'
ldap = Net::LDAP.new
ldap.host = 'localhost' 
ldap.port = 10389
ldap.auth "uid=admin,ou=system", "secret"
ldap.bind

with LDAP server running at the address you provide, and admin user configured.

Actual Behavior

$ irb
Configured by ~/.irbrc
irb(main):001:0> require 'net-ldap'
=> true
irb(main):002:0> ldap = Net::LDAP.new
=> #<Net::LDAP:0x20d3e657 @connect_timeout=nil, @force_no_page=false, @host="127.0.0.1", @hosts=nil, @auth={:method=>:anonymous}, @encryption=nil, @base="dc=com", @port=389, @open_connection=nil, @instrumentation_service=nil, @verbose=false>
irb(main):003:0> ldap.host = 'localhost'
=> "localhost"
irb(main):004:0> ldap.port = 10389
=> 10389
irb(main):005:0> ldap.auth "uid=admin,ou=system", "secret"
=> {:method=>:simple, :username=>"uid=admin,ou=system", :password=>"secret"}
irb(main):006:0> ldap.bind
Java::JavaNioChannels::NotYetConnectedException:
    from sun.nio.ch.SocketChannelImpl.ensureWriteOpen(SocketChannelImpl.java:253)
    from sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:440)
    from org.jruby.util.io.PosixShim.write(PosixShim.java:106)
    from org.jruby.util.io.OpenFile$3.run(OpenFile.java:1334)
    from org.jruby.util.io.OpenFile$3.run(OpenFile.java:1325)
    from org.jruby.RubyThread.executeTask(RubyThread.java:1464)
    from org.jruby.util.io.OpenFile.writeInternal(OpenFile.java:2233)
    from org.jruby.util.io.OpenFile.binwrite(OpenFile.java:2174)
    from org.jruby.util.io.OpenFile.fwrite(OpenFile.java:2038)
    from org.jruby.RubyIO.write(RubyIO.java:1437)
    from org.jruby.RubyIO.write(RubyIO.java:1409)
    from org.jruby.RubyIO$INVOKER$i$1$0$write.call(RubyIO$INVOKER$i$1$0$write.gen)
    from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:313)
    from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:163)
    from org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:316)
    from org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:77)
... 194 levels...
    from org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:165)
    from org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:197)
    from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:313)
    from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:163)
    from Users.gregc.$_dot_rbenv.versions.jruby_minus_9_dot_1_dot_0_dot_0.bin.irb.invokeOther3:start(/Users/gregc/.rbenv/versions/jruby-9.1.0.0/bin/irb)
    from Users.gregc.$_dot_rbenv.versions.jruby_minus_9_dot_1_dot_0_dot_0.bin.irb.RUBY$script(/Users/gregc/.rbenv/versions/jruby-9.1.0.0/bin/irb:13)
    from java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:566)
    from org.jruby.ir.Compiler$1.load(Compiler.java:111)
    from org.jruby.Ruby.runScript(Ruby.java:833)
    from org.jruby.Ruby.runScript(Ruby.java:825)
    from org.jruby.Ruby.runNormally(Ruby.java:760)
    from org.jruby.Ruby.runFromMain(Ruby.java:579)
    from org.jruby.Main.doRunFromMain(Main.java:425)
    from org.jruby.Main.internalRun(Main.java:313)
    from org.jruby.Main.run(Main.java:242)
    from org.jruby.Main.main(Main.java:204)irb(main):007:0>
irb(main):008:0* exit

This code has been running fine on various 1.7.x versions of jruby over the past year or two.

I first saw the broken behaviour on jruby-9.1.0.0 on a Sun box running 5.11 11.2 sun4v spare sun4v.

@headius
Copy link
Member

headius commented May 9, 2016

Hmm, I do recall patching bind in 9.1. Something must have regressed in that change. Investigating.

@headius
Copy link
Member

headius commented May 9, 2016

Well my one change to bind appears to be 1d21abc but reverting that doesn't fix anything. Will bisect.

@headius
Copy link
Member

headius commented May 9, 2016

Strange...the script you provided gives me this error on 9.0.5.0:

$ rvm jruby-9.0.5.0 do jruby blah.rb
Net::LDAP::Error: Bad file descriptor - No message available
  open_connection at /Users/headius/.rvm/gems/jruby-9.0.5.0/gems/net-ldap-0.14.0/lib/net/ldap/connection.rb:63
           socket at /Users/headius/.rvm/gems/jruby-9.0.5.0/gems/net-ldap-0.14.0/lib/net/ldap/connection.rb:679
   new_connection at /Users/headius/.rvm/gems/jruby-9.0.5.0/gems/net-ldap-0.14.0/lib/net/ldap.rb:1311
    block in bind at /Users/headius/.rvm/gems/jruby-9.0.5.0/gems/net-ldap-0.14.0/lib/net/ldap.rb:854
       instrument at /Users/headius/.rvm/gems/jruby-9.0.5.0/gems/net-ldap-0.14.0/lib/net/ldap/instrumentation.rb:19
             bind at /Users/headius/.rvm/gems/jruby-9.0.5.0/gems/net-ldap-0.14.0/lib/net/ldap.rb:848
            <top> at blah.rb:6

I guess I should have confirmed that attempting to bisect :-)

@headius
Copy link
Member

headius commented May 9, 2016

Ok, I'm not sure about the 9.0.5.0 failure, but I can reproduce your error pretty easily on 9.1:

[] ~/projects/jruby $ jruby -rsocket -e "p Socket.tcp('google.com', 80, {:connect_timeout=>5}).write('foo')"
Unhandled Java exception: java.nio.channels.NotYetConnectedException
java.nio.channels.NotYetConnectedException: null
      ensureWriteOpen at sun/nio/ch/SocketChannelImpl.java:274
                write at sun/nio/ch/SocketChannelImpl.java:461
                write at org/jruby/util/io/PosixShim.java:106
                  run at org/jruby/util/io/OpenFile.java:1334
                  run at org/jruby/util/io/OpenFile.java:1325
          executeTask at org/jruby/RubyThread.java:1464
        writeInternal at org/jruby/util/io/OpenFile.java:2233
             binwrite at org/jruby/util/io/OpenFile.java:2174
               fwrite at org/jruby/util/io/OpenFile.java:2038
                write at org/jruby/RubyIO.java:1437
                write at org/jruby/RubyIO.java:1409
         cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:313
                 call at org/jruby/runtime/callsite/CachingCallSite.java:163
                <top> at -e:1
  invokeWithArguments at java/lang/invoke/MethodHandle.java:627
                 load at org/jruby/ir/Compiler.java:111
            runScript at org/jruby/Ruby.java:833
            runScript at org/jruby/Ruby.java:825
          runNormally at org/jruby/Ruby.java:760
          runFromMain at org/jruby/Ruby.java:579
        doRunFromMain at org/jruby/Main.java:425
          internalRun at org/jruby/Main.java:313
                  run at org/jruby/Main.java:242
                 main at org/jruby/Main.java:204


[] ~/projects/jruby $ jruby -rsocket -e "p Socket.tcp('google.com', 80).write('foo')"
3

Looks like we're just not handling options to Addrinfo properly. I will try to patch this quickly for 9.1.1.0 and we'll try to prioritize the rework of Addrinfo and Socket.

@headius
Copy link
Member

headius commented May 9, 2016

FWIW my ruby-2.3+socket branch does not work either.

@headius
Copy link
Member

headius commented May 9, 2016

Ok, I think I have it.

Prior to 9.1 we were using Ruby 2.2 stdlib, which had different init logic for Socket.tcp (logic which apparently had some other flaws). With the 9.1 update of stdlib to 2.3, the following logic is now present for doing timed-out connections:

Called from Socket.tcp in socket.rb:

  def connect_internal(local_addrinfo, timeout=nil) # :yields: socket
    sock = Socket.new(self.pfamily, self.socktype, self.protocol)
    begin
      sock.ipv6only! if self.ipv6?
      sock.bind local_addrinfo if local_addrinfo
      if timeout
        case sock.connect_nonblock(self, exception: false)
        when 0 # success or EISCONN, other errors raise
          break
        when :wait_writable
          sock.wait_writable(timeout) or
            raise Errno::ETIMEDOUT, 'user specified timeout'
        end while true
...

I think this is simply our connect_nonblock not working properly.

@headius
Copy link
Member

headius commented May 9, 2016

Oh, silly me...the BadDescriptorException is probably because I don't have an LDAP server running locally.

I have pushed a fix in 015d17c. We were observing the exception: false passed to connect_nonblock, but then we weren't returning the symbol indicating the connect was still in progress.

As for testing...there's a very complete set of specs in the rubysl-socket gem that I've been using for my branch, and there's tests for this very behavior in MRI's suite. We do not run either right now due to other issues, but we will soon. I did not write any additional tests for my commit.

@gregclar Would it be possible for you to verify this fixes your issue? I had some trouble getting a proper LDAP server running on my OS X machine.

@headius
Copy link
Member

headius commented May 9, 2016

I've started a build of our nightly dist. Once complete it will be available at http://ci.jruby.org.

@headius headius closed this as completed May 9, 2016
@gregclar
Copy link
Author

Thanks @headius.

Trying to confirm.

I downloaded

      10697038 B  2016-05-09T04:38:14.000Z  snapshots/master/jruby-src-9.1.0.0.tar.gz  

I executed ./mvnw

I got as far as this error to do with rubygems:json:gem:1.8.3 in maven gems:

Downloaded: mavengem:https://rubygems.org/rubygems/rdoc/4.2.0/rdoc-4.2.0.gem (718 KB at 164.6 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/bouncycastle/bcpkix-jdk15on/1.54/bcpkix-jdk15on-1.54.jar
Downloading: https://repo.maven.apache.org/maven2/org/bouncycastle/bcprov-jdk15on/1.54/bcprov-jdk15on-1.54.jar
Downloading: https://repo.maven.apache.org/maven2/rubygems/jruby-readline/1.0/jruby-readline-1.0.gem
Downloading: https://repo.maven.apache.org/maven2/rubygems/json/1.8.3/json-1.8.3.gem
Downloaded: https://repo.maven.apache.org/maven2/org/bouncycastle/bcpkix-jdk15on/1.54/bcpkix-jdk15on-1.54.jar (658 KB at 118.4 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/rubygems/jruby-readline/1.0/jruby-readline-1.0.gem (244 KB at 43.5 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/bouncycastle/bcprov-jdk15on/1.54/bcprov-jdk15on-1.54.jar (3201 KB at 267.8 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] JRuby .............................................. SUCCESS [  0.944 s]
[INFO] JRuby Core ......................................... SUCCESS [ 18.256 s]
[INFO] JRuby Truffle ...................................... SUCCESS [ 21.988 s]
[INFO] JRuby Lib Setup .................................... FAILURE [01:24 min]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:11 min
[INFO] Finished at: 2016-05-10T10:36:52+10:00
[INFO] Final Memory: 64M/165M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project jruby-stdlib: Could not resolve dependencies for project org.jruby:jruby-stdlib:jar:9.1.0.0: Could not find artifact rubygems:json:gem:1.8.3 in mavengems (mavengem:https://rubygems.org) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :jruby-stdlib

I tried to run jruby anyway and I got:

$ jruby -v
jruby 9.1.0.0 (2.3.0) 2016-05-09 fffffff Java HotSpot(TM) 64-Bit Server VM 23.21-b01 on 1.7.0_21-b12 +jit [darwin-x86_64]


$ gem list --local
/Users/gregc/.rbenv/versions/jruby-9.1.0.0-snapshot/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:1:in `require':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.
LoadError: no such file to load -- psych
           require at org/jruby/RubyKernel.java:944
           require at /Users/gregc/.rbenv/versions/jruby-9.1.0.0-snapshot/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:55
             <top> at /Users/gregc/.rbenv/versions/jruby-9.1.0.0-snapshot/lib/ruby/stdlib/yaml.rb:6
           require at org/jruby/RubyKernel.java:944
            (root) at /Users/gregc/.rbenv/versions/jruby-9.1.0.0-snapshot/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:1
           require at /Users/gregc/.rbenv/versions/jruby-9.1.0.0-snapshot/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:55
         load_yaml at /Users/gregc/.rbenv/versions/jruby-9.1.0.0-snapshot/lib/ruby/stdlib/rubygems.rb:680
         load_file at /Users/gregc/.rbenv/versions/jruby-9.1.0.0-snapshot/lib/ruby/stdlib/rubygems/config_file.rb:336
        initialize at /Users/gregc/.rbenv/versions/jruby-9.1.0.0-snapshot/lib/ruby/stdlib/rubygems/config_file.rb:198
  do_configuration at /Users/gregc/.rbenv/versions/jruby-9.1.0.0-snapshot/lib/ruby/stdlib/rubygems/gem_runner.rb:75
             <top> at /Users/gregc/.rbenv/versions/jruby-9.1.0.0-snapshot/lib/ruby/stdlib/rubygems/gem_runner.rb:40
              load at org/jruby/RubyKernel.java:962
             <top> at /Users/gregc/.rbenv/versions/jruby-9.1.0.0-snapshot/bin/gem:4

Currently stuck and unable to confirm. (Not very familiar with this process, so might be doing plenty wrong.)

@headius
Copy link
Member

headius commented May 10, 2016

Sorry, the build that would have published last night failed. I fixed that up earlier today and there should be a fresh 9.1 binary snapshot (you should get the -bin tarball) at the same place.

This should be the URL for it: http://ci.jruby.org/snapshots/master/jruby-bin-9.1.0.0200.tar.gz

Otherwise, I'm about to start a fixed CI dist build (we had not updated dev version yet) that will be numbered 9.1.1.0-SNAPSHOT...should be available in the next hour.

@gregclar
Copy link
Author

Thanks @headius.

Fix confirmed with the snapshot: 32707415 B 2016-05-10T22:12:46.000Z snapshots/master/jruby-bin-9.1.1.0-SNAPSHOT.tar.gz

Set up:

$ jruby -v
jruby 9.1.1.0-SNAPSHOT (2.3.0) 2016-05-10 a185e90 Java HotSpot(TM) 64-Bit Server VM 23.21-b01 on 1.7.0_21-b12 +jit [darwin-x86_64]



$ gem install net-ldap
Fetching: net-ldap-0.14.0.gem (100%)
Successfully installed net-ldap-0.14.0
1 gem installed

$ gem list --local

*** LOCAL GEMS ***

jar-dependencies (default: 0.3.2)
jruby-openssl (0.9.15 java)
json (1.8.3 java)
minitest (default: 5.4.1)
net-ldap (0.14.0)
net-telnet (default: 0.1.1)
power_assert (default: 0.2.3)
psych (2.0.17 java)
racc (1.4.13 java)
rake (default: 10.4.2)
rdoc (default: 4.2.0)
test-unit (default: 3.1.1)

The test:

$ irb
Configured by ~/.irbrc
irb(main):001:0> require 'net-ldap'
=> true
irb(main):002:0> ldap = Net::LDAP.new
=> #<Net::LDAP:0x69412fa7 @connect_timeout=nil, @force_no_page=false, @host="127.0.0.1", @hosts=nil, @auth={:method=>:anonymous}, @encryption=nil, @base="dc=com", @port=389, @open_connection=nil, @instrumentation_service=nil, @verbose=false>
irb(main):003:0> ldap.host = 'localhost'
=> "localhost"
irb(main):004:0> ldap.port = 10389
=> 10389
irb(main):005:0> ldap.auth "uid=admin,ou=system", "secret"
=> {:method=>:simple, :username=>"uid=admin,ou=system", :password=>"secret"}
irb(main):006:0> ldap.bind
=> true

Getting "true" (or at least not an exception) is the expected result.

I appreciate your rapid response. Thanks very much.

@gregclar
Copy link
Author

@headius jruby 9.1.1.0-SNAPSHOT fixes the problem, but my application is still failing apparently because the .war file contains the jruby 9.1.0.0 runtime via the jruby-jars-9.1.0.0 gem. (https://rubygems.org/gems/jruby-jars/versions/9.1.0.0)

There is no jruby-jars-9.1.1.0 gem yet. Anything you can suggest? Do you expect a jruby-jars-9.1.1.0 gem soon?

@headius
Copy link
Member

headius commented May 11, 2016

The release of 9.1.1.0 will be within a week for sure. You can try to grab a snapshot from http://ci.jruby.org until then. Thanks for confirming!

@gregclar
Copy link
Author

Thanks @headius!

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

2 participants