denna

denna

Difficulty to understand GenServer error message triggered by reply

I accidentally called GenServer.reply(from, :ok) twice so I got the following error message in my logs. For me the message is rather cryptic. What in the message could point me to the fact that i called reply twice?

00:47:16.704 [error] [message: {#Reference<0.4144651693.395575298.249020>, :ok}, module: SCs, name: #PID<0.196.0>]

Most Liked

ityonemo

ityonemo

so here’s how to read that error:

if you see {#Reference…, } that is the signature of a gen_server call reply. the module: … is the module of the genserver that received the stray reply. Unfortunately, the source gen_server cannot be easily known, so I would say the best you can do is look at and try to figure out what could have emitted that. In the case of :ok, you might have to look in a lot of places, ha.

you do NOT want to replace the logger for stray messages. i have pushed code to prod that I was able to debug because these errors showed up in my monitoring months later (it wasn’t diminishing the user experience in a knowable way, but it was nice to be able to sleep sounder at night)

ityonemo

ityonemo

ah. In that case I recommend this:

defmodule SCs do

   # ... SCs code

  def handle_info(msg, state) do
    msg |> IO.inspect(label: "message")
    state |> IO.inspect(label: "state")
    {:noreply, state}
  end
end
hauleth

hauleth

I cannot reproduce that:

defmodule Foo do
  use GenServer

  def init(_), do: {:ok, []}

  def handle_call(msg, from, state) do
    IO.inspect(msg, label: __MODULE__)
    GenServer.reply(from, :ok)
    GenServer.reply(from, :ok)
    {:noreply, state}
  end
end

{:ok, pid} = GenServer.start_link(Foo, [])

IO.inspect GenServer.call(pid, :test)

Output

Elixir.Foo: :test
:ok

Edit, you probably run it from other GenServer that has handle_info created that will log error on unknown message. Check that.

ityonemo

ityonemo

I think that’s the default GenServer logger.

defmodule Foo do
  use GenServer
  def init(_), do: {:ok, nil}
  def handle_call({:call, pid}, _from, _) do
    GenServer.call(pid, :foo)
    {:reply, :ok, nil}
  end
end

defmodule Bar do
  use GenServer
  def init(_), do: {:ok, nil}
  def handle_call(call, from, _) do
    call |> IO.inspect(label: "14")
    GenServer.reply(from, :ok)
    GenServer.reply(from, :ok)
    {:noreply, nil}
  end
end

iex(4)> {:ok, foo} = GenServer.start_link(Foo, nil)
{:ok, #PID<0.145.0>}
iex(5)> {:ok, bar} = GenServer.start_link(Bar, nil)
{:ok, #PID<0.147.0>}
iex(6)> GenServer.call(foo, {:call, bar})
14: :foo
:ok
iex(7)> 
10:50:28.689 [error] [message: {#Reference<0.2646108517.405536772.190147>, :ok}, module: Foo, name: #PID<0.145.0>]
hauleth

hauleth

I have created issue with that problem:

And already provided PR that solves it in this particular case (but it also revealed bigger problem there):

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; someth...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

We're in Beta

About us Mission Statement