Skip to content

THRIFT-6560: Keep Ruby SSLServerSocket#accept transports open when called from a rescue clause - #4196

Merged
kpumuk merged 1 commit into
apache:masterfrom
kpumuk:rb-ssl-accept-in-rescue
Nov 18, 2026
Merged

kpumuk merged 1 commit into
apache:masterfrom
kpumuk:rb-ssl-accept-in-rescue

Conversation

@kpumuk

@kpumuk kpumuk commented Nov 17, 2026

Copy link
Copy Markdown
Member

Thrift::SSLServerSocket#accept closed the accepted socket in its ensure block whenever $! was set. $! is the exception the calling thread is currently handling, not only one raised by accept. A caller that ran accept inside a rescue clause, such as a custom accept loop retrying after an error, got back a transport whose socket was already closed. The client finished its TLS handshake, but the server could not read its request.

The accepted transport is assigned as the last step of accept. The ensure block now closes the socket only when that transport is still nil. Any exception, Thread#kill or Timeout before the handoff finishes leaves it nil, so the socket is still closed. The separate $! and "aborting" checks are no longer needed. The in-tree servers call accept outside a rescue clause and are not affected.

Reproduction, from lib/rb (also in THRIFT-6560):

transport = begin
  raise "caller error"
rescue
  server.accept # Thrift::SSLServerSocket, client sends "ping" over TLS
end
puts "open?=#{transport.open?}"
puts "read=#{transport.read(4).inspect}"

On 50242d7ea1, with and without the native extension:

open?=false
Thrift::TransportException: closed stream

With this change:

open?=true
read="ping"
  • Did you create an Apache Jira ticket? (THRIFT-6560)
  • If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
  • Did you squash your changes to a single commit? (not required, but preferred)
  • Did you do your best to avoid breaking changes? If one was needed, did you label the Jira ticket with "Breaking-Change"?
  • CI required for this change.

…lled from a rescue clause

Client: rb

SSLServerSocket#accept closed the accepted socket in its ensure block
whenever $! was set. $! holds the exception the calling thread is
handling, not one raised by accept, so a caller running accept inside a
rescue clause received a transport whose socket was already closed.

The accepted transport is assigned as the method's last step, so close
the socket only when it is still nil. That covers exceptions, Thread#kill
and Timeout during the handshake or transport handoff.

Generated-By: amp/0.0.1794916837-g564d50 (model: anthropic/claude-opus-5-5; operator: kpumuk@apache.org)
Copilot AI balanced review requested due to automatic review settings November 17, 2026 23:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@mergeable mergeable Bot added the ruby Pull requests that update Ruby code label Nov 17, 2026
@kpumuk
kpumuk merged commit 29ea1b2 into apache:master Nov 18, 2026
93 checks passed
@kpumuk
kpumuk deleted the rb-ssl-accept-in-rescue branch November 18, 2026 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ruby Pull requests that update Ruby code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants