jruby-openssl
jruby-openssl copied to clipboard
SSLSocket can't be created from UNIXSocket
Copying https://github.com/jruby/jruby/issues/2992 here per @headius suggestion, see https://github.com/jruby/jruby/issues/2992#issuecomment-106607106 for rationale. Testcase:
require 'socket'
require 'openssl'
from, to = UNIXSocket.pair
ssl_to = OpenSSL::SSL::SSLSocket.new(to)
ssl_to.write('foo')
fails with
SSLSocket.java:858:in `getSocketChannel': java.lang.ClassCastException: jnr.unixsocket.UnixSocketChannel cannot be cast to java.nio.channels.SocketChannel
from SSLSocket.java:726:in `checkClosed'
from SSLSocket.java:687:in `do_syswrite'
from SSLSocket.java:711:in `syswrite'
from SSLSocket$INVOKER$i$1$0$syswrite.gen:-1:in `call'
from CachingCallSite.java:313:in `cacheAndCall'
from CachingCallSite.java:163:in `call'
from InterpreterEngine.java:292:in `processCall'
from StartupInterpreterEngine.java:78:in `interpret'
from InterpreterEngine.java:84:in `interpret'
from MixedModeIRMethod.java:199:in `INTERPRET_METHOD'
from MixedModeIRMethod.java:185:in `call'
from DynamicMethod.java:205:in `call'
from CachingCallSite.java:313:in `cacheAndCall'
from CachingCallSite.java:163:in `call'
from InterpreterEngine.java:292:in `processCall'
from StartupInterpreterEngine.java:78:in `interpret'
from InterpreterEngine.java:84:in `interpret'
from MixedModeIRMethod.java:199:in `INTERPRET_METHOD'
from MixedModeIRMethod.java:185:in `call'
from DynamicMethod.java:205:in `call'
from CachingCallSite.java:313:in `cacheAndCall'
from CachingCallSite.java:163:in `call'
from /tmp/socket.rb:-1:in `invokeOther9:write'
from /tmp/socket.rb:6:in `RUBY$script'
from MethodHandle.java:625:in `invokeWithArguments'
from Compiler.java:111:in `load'
from Ruby.java:833:in `runScript'
from Ruby.java:822:in `runScript'
from Ruby.java:752:in `runNormally'
from Ruby.java:574:in `runFromMain'
from Main.java:401:in `doRunFromMain'
from Main.java:296:in `internalRun'
from Main.java:225:in `run'
from Main.java:197:in `main'
on JRuby jruby 9.0.0.0-SNAPSHOT (2.2.2) 2015-05-26 78b009c Java HotSpot(TM) 64-Bit Server VM 25.45-b02 on 1.8.0_45-b14 +jit [darwin-x86_64], no error on MRI (tested with 1.9 & 2.2).
+1 The same for jruby-9.1.6.0
Here we have a commit that provides a TODO JNR. We need to ask @kares. What will be the proper way to implement this todo?
Still an issue with current jruby-openssl.
Basically the problem here is that jruby-openssl expects any socket it wraps to extend the JDK socket class, but our UNIXSocket lives in a different class heirarchy. The most straightforward fix would be to make jruby-openssl use shared superclasses like AbstractSelectableChannel and Readable/WritableByteChannel, but it's tricky.