fix: add parentheses to is_a? call in SSEClient#close#625
Open
dan98765 wants to merge 1 commit into
Open
Conversation
Without explicit parentheses, Ruby parses the condition as: @socket.is_a?(OpenSSL::SSL::SSLSocket && @config.debug_enabled) Since SSLSocket is truthy, && returns the right operand (a boolean), and is_a?(true/false) raises TypeError: class or module required. This fires on every SSE socket close and is caught by the rescue StandardError block, producing error-level log entries. Fixes splitio#623.
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.
What did you accomplish?
Fixed a
TypeError: class or module requiredinSSEClient#close(line 50 oflib/splitclient-rb/sse/event_source/client.rb).Without explicit parentheses, Ruby parses:
as:
Since
OpenSSL::SSL::SSLSocketis truthy,&&evaluates and returns the right operand (@config.debug_enabled, a boolean). Thenis_a?(true)oris_a?(false)raisesTypeError.The
rescue StandardErrorblock catches it so it doesn't crash, but it fires on every SSE socket close and produces error-level log entries.The fix adds explicit parentheses:
@socket.is_a?(OpenSSL::SSL::SSLSocket).Note that line 48 has a similar
is_a?call without&&, so it parses correctly and doesn't need a change.Fixes #623.
How to test new changes?
The fix is a Ruby parsing issue, not a logic change. You can verify the parsing difference in an IRB session:
Extra Notes
This was introduced in 8.11.0 when the
&& @config.debug_enabledguard was added to theis_a?check.