How to diagnose out of memory errors?

Have the following log from an out of memory error:

2024-06-30 06:48:25.090 [error]  GenServer #PID<0.5163.0> terminating
** (stop) killed
Last message: {:EXIT, #PID<0.5161.0>, :killed}
2024-06-30 06:48:30.091 [error]  GenServer #PID<0.5150.0> terminating
** (stop) killed
Last message: {:EXIT, #PID<0.5148.0>, :killed}
2024-06-30 06:48:30.257 [error]  GenServer #PID<0.3989.0> terminating
** (ArgumentError) errors were found at the given arguments:

  * 1st argument: the table identifier does not refer to an existing ETS table

    (stdlib 5.2.1) :ets.lookup_element(:ranch_server, {:listener_sup, TeiserverWeb.Endpoint.HTTP}, 2)
    (ranch 1.8.0) /build/deps/ranch/src/ranch_server.erl:101: :ranch_server.get_listener_sup/1
    (ranch 1.8.0) /build/deps/ranch/src/ranch.erl:282: :ranch.get_status/1
    (ranch 1.8.0) /build/deps/ranch/src/ranch.erl:186: :ranch.suspend_listener/1
    (plug_cowboy 2.6.1) lib/plug/cowboy/drainer.ex:99: Plug.Cowboy.Drainer.suspend_listener/1
    (elixir 1.14.5) lib/enum.ex:4197: Enum.filter_list/2
    (plug_cowboy 2.6.1) lib/plug/cowboy/drainer.ex:94: Plug.Cowboy.Drainer.drain/2
    (stdlib 5.2.1) gen_server.erl:1143: :gen_server.try_terminate/3
Last message: {:EXIT, #PID<0.3745.0>, :shutdown}

What can I do to figure out the root cause?

You can start getting the erl_crash.dump file and running crashdump_viewer.start from an iex session to explore the dump.

After that if you want to understand what is happening I recommend checking the Erlang oficial docs about the erl_crash.dump and the chapters 5 and 6 of Erlang in Anger.

5 Likes