lorecrafting
For some reason i’m getting this error:
[error] GenServer KioskTracker_shard10 terminating
** (stop) exited in: GenServer.call(KioskTracker_shard10, {:list, “room:kiosk”}, 5000)
** (EXIT) process attempted to call itself
It’s erroring out on the Phoenix.Tracker.list call.
What is the proper way to access the list of tracked connections within the handle_diff callback function of a Phoenix Tracker?
Thanks!
def handle_diff(diff, state) do
kiosks = Phoenix.Tracker.list(__MODULE__, "room:kiosk")
IO.puts("KIOSKS CONNECTED")
IO.inspect(kiosks)
for {topic, {joins, leaves}} <- diff do
for {key, meta} <- joins do
IO.puts("presence join: key \"#{key}\" with meta #{inspect(meta)}")
# This stuff might be for distributed system with more than one node, look into it later
# 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)}")
# This stuff might be for distributed system with more than one node, look into it later
# msg = {:leave, key, meta}
# Phoenix.PubSub.direct_broadcast!(state.node_name, state.pubsub_server, topic, msg)
end
end
{:ok, state}
end
Blockquote
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sb8244
This might be an XY problem. What are you looking to achieve?
Without knowing much about your use case, you could spawn the with that needs the list of kiosks. However, you can’t do that if you need it for the return of the handle diff (I have a hard time envisioning a use case for that)
lorecrafting
I think you are right, this may be an XY problem and I might just be banging my head with very limited knowledge in Elixir =D
The problem i’m trying to solve is to shut off the ability to place an order on a mobile app if the separate web kiosk is not open.
The way i’m trying to implement it is in the handle_diff callback, whoever ‘leaves’ the channel will have their mobile app ordering shut off via a feature flag platform (LaunchDarkly).
However, there may be two or three different kiosks up at the same time for the same tenant, and wanted it to shut off if only ALL of them were off. So i was going to retrieve the existing list or presence of connections and check if there are no other kiosks of the same tenant on the list.
Is handle_diff the proper place to write all this logic or should I put it in a different module?
Thanks!
lorecrafting
Hmm.. I’m trying to implement spawning another process and calling the Track function inside of it but I get this error:
Is it saying the second item in the tuple can’t be a string?
If I do Phoenix.Tracker.list(KioskTracker, “room:kiosk”) In iex it works, but that exact function doesn’t work in the spawning function.
Thanks again for the help while i’m diving straight into this world!
sb8244
I’m pretty sure that’s from the receive. The line number will tell you exactly
Regardless, you can’t block the receive like that. When I recommended a spawn, I was talking purely about for side effect code. If you want the tracker result as part of processing the diff, then I think you’re blocked.
What are you trying to do? I’m almost certain that you shouldn’t go down this path.
lorecrafting
I’ll take your advice and rethink the solution. I may need help with it as my knowledge is very limited.
Within the receive, or once I somehow have the list of connected kiosks, i wanted to make sure there aren’t any identical kiosks in the list to the one that just disconnected. This is solving for the case that there are two or more kiosks up that belong to the same tenant.
Only when all kiosks of the a specific tenant has disconnected, only then do I want to fire off instructions that turn off mobile ordering functionality.
So in the handle_diff i need two pieces of information:
So that I can check the list to see if there are any other kiosks out there belonging to the same tenant. If there aren’t, then i’ll fire off the instructions to shut off mobile ordering. If there is then do nothing.
Would the alternate solution be to send a message from the handle_diff to another process to handle all the logic?
Again, thanks!
lorecrafting
Yup you’re right, it errors out in the receive.
lorecrafting
Ah! I’ve uncommented out PhoenixPubSub.direct_broadcast! functions and an now trying to do the logic in the Channels. Going to play around with that and think this may be a better direction!
sb8244
The one thing to consider with
handle_diffis that it will execute on every node in the cluster for a given change. This means that if there’s some logic you want to do once, it will actually run N times.The Channel approach may work here (especially if intercepting
handle_diff). You can execute code to check the kiosks and shut down in that case. I normally recommend Tracker, but Presence would actually fit pretty well if you’re intercepting handle_diff. It’s just tracker + broadcasting the diff to that topic.lorecrafting
Awesome, thanks for guidance!
vbroskas
How did you end up solving this issue? Im getting the same error when trying to call
Phoenix.Tracker.list(tracker_name, topic)from either inside myhandle_diff()callback or another module.I thought of intercepting
presence_diffin my channel, and each time there was aleaveI could make a call toPhoenix.Tracker.list(). However Im finding that while interceptingprescence_diffit doesn’t seem to fire when the last person subscribed to a topic leaves (I assume this is because the last person leaving kills thepresencefor that topic)