Skip to content

Commit fdd5a56

Browse files
committed
non-connected ssl socket raises EPIPE on connect_nonblock (MRI compat)
1 parent 1091e80 commit fdd5a56

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/main/java/org/jruby/ext/openssl/SSLSocket.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,16 @@ private IRubyObject connectImpl(final ThreadContext context, final boolean block
266266
forceClose();
267267
throw newSSLError(context.runtime, e);
268268
}
269+
catch (NotYetConnectedException e) {
270+
throw newErrnoEPIPEError(context.runtime, "SSL_connect");
271+
}
269272
return this;
270273
}
271274

275+
private static RaiseException newErrnoEPIPEError(final Ruby runtime, final String detail) {
276+
return Utils.newError(runtime, runtime.getErrno().getClass("EPIPE"), detail);
277+
}
278+
272279
@JRubyMethod
273280
public IRubyObject accept(final ThreadContext context) {
274281
return acceptImpl(context, true, true);

src/test/ruby/ssl/test_socket.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ def test_read_nonblock_no_exception
102102
end
103103
end if RUBY_VERSION > '2.2'
104104

105+
def test_connect_non_connected; require 'socket'
106+
socket = OpenSSL::SSL::SSLSocket.new(Socket.new(:INET, :STREAM))
107+
begin
108+
socket.connect_nonblock
109+
rescue => e
110+
assert_equal Errno::EPIPE, e.class
111+
puts e.inspect if $VERBOSE
112+
ensure
113+
socket.close
114+
end
115+
end if RUBY_VERSION > '2.2'
116+
105117
private
106118

107119
def server

0 commit comments

Comments
 (0)