Fl4m3Ph03n1x

Fl4m3Ph03n1x

Is it possible to use Rexbug to trace messages send/received by processes?

Background

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:

=ERROR REPORT==== 14-Jun-2019::14:31:35.089496 ===
Unexpected message: {#Ref<0.2607974300.3493068808.175359>,badarg}

Rexbug?

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

  1. Can this library help me in my task?
  2. Is it suitable for our use case? If not, what are the alternatives?

First 9 of 9 Posts Switch mode

idi527

idi527

:waving_hand:

What’s your use case exactly?


Do you want to get the incoming messages for a process?

Then maybe :sys.trace/2. Also check out sys and proc_lib — Erlang System Documentation v29.0.2. 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):

iex(2)> {:ok, agent} = Agent.start_link(fn -> 0 end) # agents are genservers
{:ok, #PID<0.111.0>}
iex(3)> send(agent, {make_ref, :badarg})
{#Reference<0.2487050872.1550581763.207046>, :badarg}
08:01:48.305 [error] Agent.Server #PID<0.111.0> received unexpected message in handle_info/2: {#Reference<0.2487050872.1550581763.207046>, :badarg}

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.

Fl4m3Ph03n1x

Fl4m3Ph03n1x OP

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 :smiley:
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.

idi527

idi527

Can you post your logger config here? And :extra_applictions from your mix.exs if possible.

NobbZ

NobbZ

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…

idi527

idi527

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}
michalmuskala

michalmuskala

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:

(<0.108.0>) <0.117.0> ! {#Ref<0.3800804343.3707502597.14282>,badarg}

Which means process <0.108.0> sent the above message to <0.117.0>.

Fl4m3Ph03n1x

Fl4m3Ph03n1x OP

Logger configs:

# Configures Elixir's Logger
config :logger, :console,
  format: "$date $time $metadata[$level] $message\n",
  metadata: [:request_id]

# Do not print debug messages in production
config :logger,
  level: :error,
  handle_otp_reports: false,
  handle_sasl_reports: false,
  truncate: :infinity

Elixir, OTP and erlang versions:

elixir 1.8.1-otp-21
erlang 21.2.6

So if I just place that in a remote iex shell connected to the application, it should work, right?
Will try it out for sure!

NobbZ

NobbZ

Try handling OTP and SASL reports via Logger, also enable more metadata, at least temporarily. If in doubt just use :all.

Then you’ll get nicer output and it’s in a single line rather then in the block like thing that you get now…

bryanhuntesl

bryanhuntesl

You could match the process identifiers and MFA on send / receive ?

— All posts loaded —

Where Next?

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement