Skip to content

fix: add parentheses to is_a? call in SSEClient#close#625

Open
dan98765 wants to merge 1 commit into
splitio:masterfrom
dan98765:fix/is_a-parens-sseclient-close
Open

fix: add parentheses to is_a? call in SSEClient#close#625
dan98765 wants to merge 1 commit into
splitio:masterfrom
dan98765:fix/is_a-parens-sseclient-close

Conversation

@dan98765

Copy link
Copy Markdown

What did you accomplish?

Fixed a TypeError: class or module required in SSEClient#close (line 50 of lib/splitclient-rb/sse/event_source/client.rb).

Without explicit parentheses, Ruby parses:

if @socket.is_a? OpenSSL::SSL::SSLSocket && @config.debug_enabled

as:

if @socket.is_a?(OpenSSL::SSL::SSLSocket && @config.debug_enabled)

Since OpenSSL::SSL::SSLSocket is truthy, && evaluates and returns the right operand (@config.debug_enabled, a boolean). Then is_a?(true) or is_a?(false) raises TypeError.

The rescue StandardError block 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:

obj = OpenSSL::SSL::SSLSocket
debug = true

# Without parens (current code) — TypeError
obj.is_a? OpenSSL::SSL::SSLSocket && debug
# => TypeError: class or module required

# With parens (this fix) — works correctly
obj.is_a?(OpenSSL::SSL::SSLSocket) && debug
# => true

Extra Notes

This was introduced in 8.11.0 when the && @config.debug_enabled guard was added to the is_a? check.

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.
@dan98765 dan98765 requested a review from a team as a code owner June 15, 2026 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError in SSEClient#close from paren-less is_a? call (8.11.0)

1 participant