Dmytro Shteflyuk created THRIFT-6117:
----------------------------------------

             Summary: Ruby SSL and Unix socket transports should reject 
duplicate opens
                 Key: THRIFT-6117
                 URL: https://issues.apache.org/jira/browse/THRIFT-6117
             Project: Thrift
          Issue Type: Bug
          Components: Ruby - Library
            Reporter: Dmytro Shteflyuk
            Assignee: Dmytro Shteflyuk


h3. Problem

THRIFT-6112 makes {{Thrift::Socket#open}} reject a second open on an 
already-open TCP transport. {{Thrift::SSLSocket}} and {{Thrift::UNIXSocket}} 
override {{open}} and bypass that check.

Calling {{open}} twice on either overriding transport creates another 
connection and replaces {{@handle}} without closing the original connection. 
The first SSL or Unix-domain socket remains live but is no longer reachable 
through the transport. A later {{close}} therefore closes only the replacement 
connection.

h3. Client impact

Applications with duplicate connection setup or retry paths can leave unused 
client and server connections open. Each orphaned connection consumes a file 
descriptor and may leave an unexpected server-side session active after the 
Thrift transport has been closed.

This also makes the SSL and Unix-domain transports inconsistent with the TCP 
transport, which reports {{TransportException::ALREADY_OPEN}} and preserves the 
existing connection.

h3. Reproduction

The Unix-domain behavior can be reproduced with a local server:

{code:ruby}
require "socket"
require "thrift"

path = "/tmp/thrift-double-open-#{Process.pid}.sock"
server = UNIXServer.new(path)
transport = Thrift::UNIXSocket.new(path)

transport.open
first_peer = server.accept
first_handle = transport.handle

transport.open
second_peer = server.accept

puts "first_handle_closed=#{first_handle.closed?}"
puts "second_handle_same=#{transport.handle.equal?(first_handle)}"
{code}

Current output:

{noformat}
first_handle_closed=false
second_handle_same=false
{noformat}

The same two-open sequence against a local TLS server reaches the equivalent 
handle-replacement path in {{Thrift::SSLSocket#open}}.

h3. Expected behavior

{{Thrift::SSLSocket#open}} and {{Thrift::UNIXSocket#open}} should reject a 
duplicate open with {{Thrift::TransportException::ALREADY_OPEN}} before 
creating another connection. The original handle and server-side session should 
remain unchanged.

The transport contract should be covered across TCP, SSL, and Unix-domain 
sockets, with real connection tests confirming that a rejected duplicate open 
does not create or orphan another peer connection.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to