Repository navigation
Forget a topic once it is left, client- or server-initiated - #95
Open
chrismccord wants to merge 1 commit into
Open
chrismccord wants to merge 1 commit into
chrismccord wants to merge 1 commit into
Conversation
A left topic (the client left it, or the server closed its channel with
phx_close) kept its join forever: the socket only marked it :closed and the
connection never dropped its join ref. A client that joins a fresh topic per
task grew both maps with every task it ever ran, and the socket, copied into
every command, grew with it. A long-lived connection that joins one channel
per short-lived task held thousands of dead joins within minutes, and every
push copied them.
TopicLeft now drops the topic's join in the socket and its join ref in the
connection. Events for a topic whose join is gone (a second close, a late
join reply) leave the socket as it is instead of crashing on a missing key.
A topic closed by an error or a refused join keeps its join for rejoin/3.
Rejoining a left topic takes join/3; rejoin/3 answers {:error, :never_joined}.
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.
A topic that was left, by the client (
leave/2) or by the server closing its channel (phx_close), keeps its join forever today. The socket only marks it:closed, and the connection never drops its join ref. A client that joins a fresh topic per short-lived task therefore grows both maps with every task it ever ran. The socket is copied into every command it sends, so each push gets slower as the dead joins pile up. On one long-lived connection that joins a channel per task, we saw thousands of dead joins after a few minutes.This change forgets a topic once it is left:
Socket.apply_event/2drops the topic's join onTopicLeft.TopicLeft, as it already does forTopicJoinFailedandTopicJoinClosed.A topic closed by an error or a refused join keeps its join, so
rejoin/3still works for it.Behavior change: after a topic is left,
rejoin/3returns{:error, :never_joined}instead of rejoining with the old params. Join it again withjoin/3. The existing "once left, a topic may be rejoined" test is updated to match.Tests: a new
test/slipstream/socket_joins_test.exscovers a left join being dropped, 500 join/leave cycles leavingjoinsempty, late events after the join is gone, error closes keeping the join, andrejoin/3on a left topic. The full suite passes (97 tests).