Skip to content

Commit 6a95403

Browse files
committed
we better not throw EOF on SSLSocket#sysclose for compatibility with MRI
1 parent dcf4bf3 commit 6a95403

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -883,12 +883,11 @@ private void forceClose() {
883883
close(true);
884884
}
885885

886-
//private boolean closed;
887-
888886
private void close(boolean force) {
889-
//closed = true;
890-
891-
if ( engine == null ) throw getRuntime().newEOFError();
887+
if ( engine == null ) {
888+
// if ( force ) throw getRuntime().newEOFError();
889+
return;
890+
}
892891

893892
engine.closeOutbound();
894893

@@ -903,8 +902,6 @@ private void close(boolean force) {
903902
}
904903
}
905904

906-
//final boolean isClosed() { return closed; }
907-
908905
@JRubyMethod
909906
public IRubyObject sysclose(final ThreadContext context) {
910907
//if ( isClosed() ) return context.runtime.getNil();

src/test/ruby/ssl/test_socket.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,16 @@ def test_attr_methods
4242
socket.inspect
4343
end
4444

45+
def test_sync_close_without_connect
46+
require 'socket'
47+
Socket.open(:INET, :STREAM) do |socket|
48+
assert ! socket.closed?
49+
ssl = OpenSSL::SSL::SSLSocket.new(socket)
50+
ssl.sync_close = true
51+
assert ! ssl.closed?
52+
ssl.close
53+
assert socket.closed?
54+
end
55+
end
56+
4557
end

0 commit comments

Comments
 (0)