ndrean
I am circling around with the following problem and no post helped me so far.
I have a GenServer module named MyApp.Repo here that runs GenServer.cast but GenServer.call returns an error and kills the process.
GenServer MyApp.Repo terminating
** (ArgumentError) unknown registry: MyApp.Repo
When I start the app, I check:
iex> Enum.member?(Process.registered(), MyApp.Repo)
=> true
The GenServer module MyApp.Repo is supervised as a child by the Application supervisor.
children = [
MyAppWeb.Telemetry,
{Phoenix.PubSub, name: MyApp.PubSub, adapter: Phoenix.PubSub.PG2},
MyApp.Repo,
MyAppWeb.Endpoint
...
MyApp.Repo module is a basic GenServer that registers a :name:
def start_link(),
do: GenServer.start_link(__MODULE__, [], name: __MODULE__)
def save_with_cast(user),
do: GenServer.cast(__MODULE__, {:new, user})
def save_with_call(user) do
IO.inspect(user, label: "CALL______")
GenServer.call(__MODULE__, {:new, user})
end
def handle_call({:new, user}, _from,_state) do
IO.puts("CALL______")
Phoenix.PubSub.broadcast_from(MyApp.PubSub, self(), @topic, {:perform_new, user})
{:reply, user, [])
end
def handle_cast({:new, user}, _state) do
Phoenix.PubSub.broadcast_from(MyApp.PubSub, self(), @topic, {:perform_new, user})
{:noreply, []}
end
def handle_info({:perform_new, message}, _state) do
...
MyApp.save_with_cast(user) runs :ok but not MyApp.save_with_call(user).
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
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
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
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 new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
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
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
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
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
msimonborg
Can you paste the implementations of
handle_cast/2andhandle_call/3, and the stacktrace of theArgumentError?ndrean
I added some code above, and the stacktrace is below:
msimonborg
Where does the
messagevariable come from?Is
MyApp.Repopubsub broadcasting to itself?What is in your
terminate/2callback? It looks like you might be trying to unregister from a nonexistent registry withRegistry.unregister(__MODULE__, key)ndrean
messagewasuserin fact, I copied the wrong one. I changed the names to be more readable.Then I added this because I saw this somewhere and wasn’t sure
OK, I removed this. Now I have a different error:
This was my inspiration
It was a typo (
:nwinstead of:newin thehandle_call).castandcallrun normal. Thanks for the guidance on thisterminatefunction. So the typo killed or stopped and the termination function destroyed things I believe.msimonborg
There it is!
unsubscribe/2, likebroadcastandsubscribeand friends, needs a valid PubSub name as the first argument.Phoenix.PubSub.unsubscribe(MyApp.PubSub, @topic)would be correct, it infers thepidto unsubscribe automatically. That is the cause of your** (ArgumentError) unknown registry: MyApp.Repo. Unsubscribing in theterminate/2callback is not necessary by the way, you are subscribed bypidwhich is automatically cleaned up if the process restarts. Also you do not need pubsub at all to send messages to yourself, just usesend(self(), {:perform_new, user})ifMyApp.Repois the only process interested in the message. And even then, you only need to do this if you require async execution, otherwise you can implement theperform_newdirectly in the original callback. Having separatecallandcasthandlers that implement the same message sending toself()like this is kind of an anti-pattern in my opinion,callimplies that it’s a synchronous operation but you are forcing it to be async so there’s no reason to have acallimplementation.All that said, this error is raising because your process is already crashing somewhere else. If you remove this
terminate/2callback entirely you may get a more helpful error message about what the real problem is.msimonborg
Double check the
handle_call/3function head, this is indicating you made a mistake there. Or you might need torecompile()your project if you’ve added this function since starting your sessionmsimonborg
With the way you’re editing your posts as you solve your problem it makes the thread harder to follow for anyone else reading it, and makes it look like I’m replying to a problem you already solved lol. Might want to post new developments as new comments especially if previous posts have already been replied to.
ndrean
ok! Thanks!
ndrean
Yes, this needs an explanation. I am “pubsubing” to other nodes, not sending messages to self()
msimonborg
Gotcha, that makes sense