Repository navigation
THRIFT-6560: Keep Ruby SSLServerSocket#accept transports open when called from a rescue clause - #4196
Merged
Merged
Conversation
…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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thrift::SSLServerSocket#acceptclosed the accepted socket in itsensureblock whenever$!was set.$!is the exception the calling thread is currently handling, not only one raised byaccept. A caller that ranacceptinside arescueclause, 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. Theensureblock now closes the socket only when that transport is stillnil. Any exception,Thread#killorTimeoutbefore the handoff finishes leaves itnil, so the socket is still closed. The separate$!and"aborting"checks are no longer needed. The in-tree servers callacceptoutside arescueclause and are not affected.Reproduction, from
lib/rb(also in THRIFT-6560):On
50242d7ea1, with and without the native extension:With this change: