Skip to content
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

Remote node doesn't receive last update right before process terminates #103

Open
tverlaan opened this issue Apr 20, 2018 · 6 comments
Open

Comments

@tverlaan
Copy link
Contributor

We use Phoenix.Tracker for keeping the state of currently active calls. Each call has a certain state in the metadata of the tracker. When a process updates the state in the terminate callback, the update of the metadata is only published locally. The remote node doesn't see this updated metadata but only sees the process leave since it terminated within the broadcast_window.

I made an example project that demoes the above scenario. You can find it here: https://github.com/tverlaan/presence_multinode

We discussed possible improvements and alternative solutions during ElixirConfEU, but we didn't come to a conclusion just yet.

@josevalim
Copy link
Member

Thanks for the report! To add more info, @chrismccord believes this happen somewhere in presence when we are squeezing the joins and leaves together to push to the client (or in the client itself). We currently treat the changes in state as a leave+join so anything that happens in between is condensed.

@tverlaan
Copy link
Contributor Author

Would it be possible to update meta when leave+join is condensed? Or will it break when another node has a presence update for the same key?

Can you point me to some documentation or a paper where I can read into the implementation by Phoenix a bit more?

@josevalim
Copy link
Member

josevalim commented May 15, 2018 via email

@tverlaan
Copy link
Contributor Author

We were "updating" meta to reflect the process is about to exit clear or fail.

I'll try to get a better understanding of the implementation to see if and/or how we can improve it. Outcome could be documentation as well I think.

@michalmuskala
Copy link
Contributor

One way to solve this would be to differentiate (I'm not really sure how) in handle_diff between process explicitly calling untrack and being removed after it died.

@josevalim
Copy link
Member

@tverlaan actually, I think when you leave, you should have the latest meta:

def handle_diff(diff, state) do
for {topic, {joins, leaves}} <- diff do
for {key, meta} <- joins do
IO.puts "presence join: key \"#{key}\" with meta #{inspect meta}"
msg = {:join, key, meta}
Phoenix.PubSub.direct_broadcast!(state.node_name, state.pubsub_server, topic, msg)
end
for {key, meta} <- leaves do
IO.puts "presence leave: key \"#{key}\" with meta #{inspect meta}"
msg = {:leave, key, meta}
Phoenix.PubSub.direct_broadcast!(state.node_name, state.pubsub_server, topic, msg)
end
end
{:ok, state}
end

This latest meta should have your latest changes. Are you using this information in the client?

In case the leave information does not have the latest meta, then that would be a bug. @michalmuskala, this should also provide you a way to pass the exit information, we could add it to the meta under a reserved key.

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

No branches or pull requests

3 participants