We have an app the keeps running. This is a OTP application that has other OTP applications as dependencies. It uses GenServers and Supervisors as do many of its dependencies.
Problem
The app doesn’t crash, but it constantly prints the following error:
I was told about this library, but after reading the README page I could not find any examples of message tracing between processes. I know Rexbug is a wrapper for the erlang counterpart, but I am not familiar with it either.
Questions
Can this library help me in my task?
Is it suitable for our use case? If not, what are the alternatives?
Do you want to get the incoming messages for a process?
Then maybe :sys.trace/2. Also check out Erlang -- sys and proc_lib. But it would be useless, since you already know the “faulty” message: {#Ref<0.2607974300.3493068808.175359>,badarg}.
Also note that unlike redbug it might cause performance problems if enabled on a busy process.
So I guess you want to either know the process that received the faulty message (that info should be printed somewhere in the rest of the error report):
Or you want to know the process that sent it. Not sure about this one, but it should be possible to find out once you know the callback module for the process that received it, look for anything that calls make_ref and sends a message to an erlang lib that might reply with a :badarg.
I already tried :erlang.trace and :erlang.trace_pattern but none of them were able to catch the process responsible. There is a chance I am miss using these tools, so I was looking for something easier the use but with a similar level of power.
This is actually fine for us. We are ok with sinking a machine if it provides us with the data we need to fix all the others. We see it as a sacrificial lamb
We are open to all avenues here.
There is no error report. The message I show in the original post is all we get to work with. The only clue OTP gives us.
Also please tell us which version of Elixir and OTP you are running @Fl4m3Ph03n1x, some of the nice Logger things are only available with more recent versions of both…
Just in case, here’s what I get in one of my apps running in a release built with erlang 21.0 and elixir 1.8 when I send one of the genservers an “unexpected” message:
[error] Worb.HiraganaSession #PID<0.2565.0> received unexpected message in handle_info/2: {#Reference<0.2424035366.4111728641.125681>, :badarg}
I’m not really sure about redbug, but with dbg captureing a process that sends {ref, :badarg} messages would look something like:
# start the logger process
:dbg.tracer()
# set the match spec to only capture {ref, :badarg} messages
# will only trace messages received by receiver, can be :_ to trace all processes as receivers
:dbg.tpe(:send, [{[receiver, {:"$1", :badarg}],[{:is_reference,:"$1"}],[]}])
# start the trace on sender, can also be :processes to trace all processes as senders
:dbg.p(sender, [:r]);
You’ll start receiving log messages in the shape of: