-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix unsubscribed
server side behavior
#23715
Conversation
Good catch. Test coverage to demonstrate the expected behavior? |
Was working on this earlier, but added a regression test to show the expected behavior. cc @matthewd since we talked about this in Campfire. |
59e908c
to
28f40a7
Compare
c.send_message command: 'subscribe', identifier: JSON.dump(channel: 'EchoChannel') | ||
assert_equal({"identifier"=>"{\"channel\":\"EchoChannel\"}", "type"=>"confirm_subscription"}, c.read_message) | ||
assert_equal(1, app.connections.count) | ||
assert_equal(1, app.connections.first.subscriptions.method(:subscriptions).call.count) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ugly (and definitely not public API), but is still necessary to demonstrate the regression test.
@jeremy updated with regression test - all set to go? |
@@ -54,7 +54,7 @@ def identifiers | |||
end | |||
|
|||
def unsubscribe_from_all | |||
subscriptions.each { |id, channel| channel.unsubscribe_from_channel } | |||
subscriptions.each { |id, channel| remove({ 'identifier' => id }) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use remove_subscription(channel)
here? This feels like unnecessary indirection (and I think I'd actually argue we don't want the log lines).
97dc23c
to
0402df5
Compare
Before this commit, the `unsubscribed` callbacks in Action Cable server side channels were never called. This is because when a WebSocket "goodbye" message was sent from the client, the Action Cable server didn't properly clean up after the now closed WebSocket. This means that memory could possibly skyrocket with this behavior, since part of this commit is to properly remove closed subscriptions from the global subscriptions hash. Say you have 10,000 users currently connected, and then all 10,000 disconnect -- before this patch, Action Cable would still hold onto information (and Ruby objects!) for all of these now dead connections.
0402df5
to
cefcc0f
Compare
Fix `unsubscribed` server side behavior
Closes #23708
Before this commit, the
unsubscribed
callbacks in Action Cable serverside channels were never called. This is because when a WebSocket
"goodbye" message was sent from the client, the Action Cable server
didn't properly clean up after the now closed WebSocket. This means that
memory could possibly skyrocket with this behavior, since part of this
commit is to properly remove closed subscriptions from the global
subscriptions hash. Say you have 10,000 users currently connected, and
then all 10,000 disconnect -- before this patch, Action Cable would
still hold onto information (and Ruby objects!) for all of these now
dead connections.
cc @dhh @matthewd