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

NullPointerException when inheriting from SSLSocket #165

Closed
ajlai opened this issue May 26, 2018 · 5 comments
Closed

NullPointerException when inheriting from SSLSocket #165

ajlai opened this issue May 26, 2018 · 5 comments

Comments

@ajlai
Copy link

ajlai commented May 26, 2018

This is using jruby-openssl 0.10.0, JRUBY_VERSION 9.1.17.0.
Discovered when doing a deeper dive on redis/redis-rb#756

require 'socket'
require 'openssl'

class InheritedSSLSocket < OpenSSL::SSL::SSLSocket
end

host = 'localhost'
port = 12345

tcp_server = TCPServer.new(host, port)

tcp_sock = TCPSocket.new(host, port)
ctx = OpenSSL::SSL::SSLContext.new

ssl_sock = InheritedSSLSocket.new(tcp_sock, ctx) # KABOOM

here's the stack trace:

Java::JavaLang::NullPointerException:
	from org.jruby.ext.openssl.SSLSocket.callSite(SSLSocket.java:149)
	from org.jruby.ext.openssl.SSLSocket.set_io_nonblock_checked(SSLSocket.java:195)
	from org.jruby.ext.openssl.SSLSocket.initialize(SSLSocket.java:183)
	from org.jruby.ext.openssl.SSLSocket$INVOKER$i$0$0$initialize.call(SSLSocket$INVOKER$i$0$0$initialize.gen)
	from org.jruby.internal.runtime.methods.JavaMethod$JavaMethodN.call(JavaMethod.java:800)
	from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:348)
	from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:193)
	from org.jruby.RubyClass.newInstance(RubyClass.java:1009)
	from org.jruby.RubyClass$INVOKER$i$newInstance.call(RubyClass$INVOKER$i$newInstance.gen)
	from org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:210)
	from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:338)
	from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:183)
	from org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:324)
	from org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:72)
	from org.jruby.ir.interpreter.Interpreter.INTERPRET_EVAL(Interpreter.java:117)
	from org.jruby.ir.interpreter.Interpreter.evalCommon(Interpreter.java:171)
... 103 levels...
	from org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:165)
	from org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:202)
	from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:318)
	from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:155)
	from usr.local.var.rbenv.versions.jruby_minus_9_dot_1_dot_17_dot_0.bin.jirb.invokeOther13:start(/usr/local/var/rbenv/versions/jruby-9.1.17.0/bin/jirb:13)
	from usr.local.var.rbenv.versions.jruby_minus_9_dot_1_dot_17_dot_0.bin.jirb.RUBY$script(/usr/local/var/rbenv/versions/jruby-9.1.17.0/bin/jirb:13)
	from java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
	from org.jruby.ir.Compiler$1.load(Compiler.java:94)
	from org.jruby.Ruby.runScript(Ruby.java:830)
	from org.jruby.Ruby.runNormally(Ruby.java:749)
	from org.jruby.Ruby.runNormally(Ruby.java:767)
	from org.jruby.Ruby.runFromMain(Ruby.java:580)
	from org.jruby.Main.doRunFromMain(Main.java:417)
	from org.jruby.Main.internalRun(Main.java:305)
	from org.jruby.Main.run(Main.java:232)
	from org.jruby.Main.main(Main.java:204)
@kares
Copy link
Member

kares commented May 27, 2018

oh yeah sorry about that - did not realize anyone would inherit OpenSSL::SSL::SSLSocket and that it would fail to find the proper call-site in such case. is this production code in redis or just a test setup?
you can simply revert to using gem 'jruby-openssl', '< 0.10' in the mean time.

@ajlai
Copy link
Author

ajlai commented May 27, 2018

Unfortunately, this is coming from production code in redis: https://github.com/redis/redis-rb/blob/e5af405bbc857300d7bcf0e0d07286d39dbe8ba0/lib/redis/connection/ruby.rb#L257

Yep, we updated the dependencies in the gemfile which seems to fix that: https://github.com/redis/redis-rb/pull/761/files

@kares
Copy link
Member

kares commented May 28, 2018

oh well.
do you guys realize you're causing double-buffering - since the SSLSocket isn't a raw read piece.
includes OpenSSL::Buffering having a read() buffer, the rest of non-blocking details doesn't need to patch sockets.

@bryonb07
Copy link

bryonb07 commented Jun 6, 2018

I just encountered this same error while running tests for an internal LDAP gem based on the net-ldap gem. The net-ldap gem throws the above error when attempting to use tls encryption under JRuby 9.2.0 while it does not under JRuby 9.1.17. I believe this is because JRuby 9.2.0 was updated to jruby-openssl 0.10.0. The net-ldap gem doesn't include jruby-openssl as a direct dependency, and doesn't appear to be actively maintained any more. So it looks like we will have to hold off from using JRuby 9.2.0 for now.

@kares
Copy link
Member

kares commented Jun 29, 2018

was resolved in 0.10.1

@kares kares closed this as completed Jun 29, 2018
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

3 participants