Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/rb/lib/thrift/transport/ssl_server_socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ def accept
accepted_transport.handle = ssl_socket
end
ensure
# Thread#kill leaves $! nil, but marks the thread as aborting.
close_accepted_socket(ssl_socket) if transport.nil? || $! || Thread.current.status == "aborting"
# transport is assigned last, so it is still nil if an exception, Thread#kill, or Timeout
# interrupts accept before then.
close_accepted_socket(ssl_socket) if transport.nil?
end

def to_s
Expand Down
22 changes: 22 additions & 0 deletions lib/rb/spec/ssl_server_socket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,28 @@
stop_thread(accept_thread)
end

it "returns an open transport when accept is called while handling an exception" do
server = build_server(client_timeout: 1)
accept_thread = Thread.new do
raise "caller error"
rescue
server.accept
end
tcp_client, ssl_client = connect_ssl_client(server)
ssl_client.write("ping")

expect(accept_thread.join(1)).not_to be_nil
transport = accept_thread.value
expect(transport).to be_open
expect(transport.read(4)).to eq("ping")
ensure
transport&.close
ssl_client&.close
tcp_client&.close
server&.close
stop_thread(accept_thread)
end

it "supports resumed client-authenticated TLS sessions" do
context = server_context
context.verify_mode = OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT
Expand Down
Loading