Skip to content

Conversation

@ggmichaelgo
Copy link
Contributor

It is possible for @stream to be nil during @stream.write.

Types of Changes

  • Bug fix.

Contribution

Comment on lines 330 to 332
if stream = @stream
if @stream
@stream.close
@stream = nil
stream.close
Copy link
Contributor

Choose a reason for hiding this comment

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

The pattern here is deliberate to set @stream to nil before calling #close which may, in theory, be a schedule point.

# Write a message to the connection stream.
#
# @parameter message [Hash] The message to write.
def write(**message)
Copy link
Contributor

Choose a reason for hiding this comment

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

If we are going to do this, I think it's better that we are explicit rather than just silently failing the write, e.g. raise IOError

Suggested change
def write(**message)
def write(**message)
raise IOError, "Connection closed!" if @stream.nil?

Copy link
Contributor

Choose a reason for hiding this comment

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

(Then, we should probably have the caller deal with this exception gracefully).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup - good idea 👍
It looks like Connection#call and Connection#dispatch already gracefully handles the IOError

@samuel-williams-shopify samuel-williams-shopify merged commit 7023b16 into main Dec 5, 2025
34 of 40 checks passed
@samuel-williams-shopify samuel-williams-shopify deleted the fix-safe-connection-flush branch December 5, 2025 01:44
@samuel-williams-shopify
Copy link
Contributor

Thanks!

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.

2 participants