Skip to content

Make Socket#transmit and #close idempotent.#6

Merged
ioquatix merged 8 commits into
socketry:mainfrom
joeljunstrom:socket-idempotent-transmit-close
May 22, 2026
Merged

Make Socket#transmit and #close idempotent.#6
ioquatix merged 8 commits into
socketry:mainfrom
joeljunstrom:socket-idempotent-transmit-close

Conversation

@joeljunstrom
Copy link
Copy Markdown
Contributor

@joeljunstrom joeljunstrom commented May 21, 2026

transmit pushed to the output queue unconditionally, raising ClosedQueueError if the socket had already been closed.

That bubbles out of ActionCable::Server::Base#restart, which calls close on every connection (which itself calls transmit to send the disconnect frame) and surfaces as a 500 on the request that triggered the reload.

Guard both methods on @output.closed? (the same primitive they mutate). The rescue ClosedQueueError covers a concurrent close racing past the check.

This kinda mirrors the question / guidance from actioncable-next#16 (comment) #close should tolerate "already closed" rather than have callers gate on it.

Not sure where is the correct seam for this! Just know that would be nice to not have my colleagues naging me about issues running this in rails development =)

Types of Changes

  • Bug fix.

Contribution

@joeljunstrom joeljunstrom force-pushed the socket-idempotent-transmit-close branch 2 times, most recently from 9d20a69 to 48a5fe4 Compare May 21, 2026 16:04
ioquatix and others added 2 commits May 22, 2026 12:26
`transmit` pushed to the output queue unconditionally, raising
`ClosedQueueError` if the socket had already been closed.

That bubbles out of `ActionCable::Server::Base#restart`, which
calls `close` on every connection (which itself calls `transmit`
to send the disconnect frame) and surfaces as a 500 on the
request that triggered the reload.

Guard both methods on `@output.closed?` (the same primitive
they mutate)

The `rescue ClosedQueueError` covers a concurrent close racing
past the check.
@ioquatix ioquatix force-pushed the socket-idempotent-transmit-close branch from 48a5fe4 to 18c411c Compare May 22, 2026 03:27
@ioquatix
Copy link
Copy Markdown
Member

@copilot resolve the merge conflicts in this pull request

@ioquatix ioquatix merged commit 05382f7 into socketry:main May 22, 2026
17 of 20 checks passed
@ioquatix
Copy link
Copy Markdown
Member

ioquatix commented May 22, 2026

I decided to revert this change.

  1. Thread::Queue#close is already idempotent (you can call it multiple times).
  2. #transmit after calling #close is a user error.

However, in principle, I agree that close should be idempotent, which it already is, and I will retain test for this behaviour.

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