Repository navigation
Conversation
Contributor
|
Hi @hsusul, we're actually doing a bunch of work on presence at the moment, so this PR is probably chasing a moving target for a bit. On this issue in particular though, the threshold for a waiting for the perm down is configurable, which I think is a better solution that leaking Phoenix Presence internals out into Realtime. But like I said, lots is changing in presence at the moment, so it might be worth waiting for that to settle in the next couple months. Thanks! |
This branch has not been deployed
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.
Summary
presence_statenow leaves out members tracked by a node that is no longer connected, while keeping the dirty ETS read from fix: dirty_list Presence #558presence_stateWhy
When a node leaves the cluster,
Phoenix.Trackersends leaves for its members but keeps their rows in each shard's ETS table untilpermdown_periodpasses (20 minutes by default).Presence.list/1filters down replicas out.PresenceHandlerbuildspresence_statefromShard.dirty_list/2, which callsState.tracked_values(shard, topic, [])with no down replicas, so it doesn't.Clients that were already joined drop the departed members when the leave arrives, about 30s after the node goes away. Clients that join later still get them in
presence_stateuntil permdown. With the default random presence key, a user who reconnects to another node shows up twice to new joiners. This happens whenever a node leaves and doesn't come back under the same name, for example a machine replaced in a deploy or a scale-down.The fix reads the shard table with
:ets.selectand drops members whosenode(pid)isn't in[node() | Node.list()]. The tracked pid is always the channel process on its own node, so the pid's node is the replica's node.Validation
left: %{"remote" => %{"metas" => [...]}},right: %{}. The assertion before the peer stops, that"remote"is present, passes either way, so the test also guards against filtering out live memberstest/realtime_web/channels/realtime_channel/presence_handler_test.exswith the new file: 71 passedtest/integration/rt_channel/presence_test.exsandtest/integration/distributed_realtime_channel_test.exs: 46 passedmix format --check-formatted,MIX_ENV=test mix credo --stricton the changed files,git diff --checkmix compile --force --warnings-as-errors,MIX_ENV=test mix compile --warnings-as-errorsandmix format --check-formattedwith the CI-pinned Elixir 1.19.5 / OTP 28 (elixir:1.19.5-otp-28container)I didn't run the full suite or dialyzer locally.