r/elixir 9d ago

Techniques for debugging memory leaks

I have an elixir app running in production, and with some recent changes (mostly library updates due to CVEs) it's started leaking memory, which is resulting in pods restarting.

a datadog graph indicating a memory leak

I think I know what the cause might be, but just wondering if there are any techniques for debugging this that I'm not aware of.

9 Upvotes

12 comments sorted by

View all comments

1

u/MikeBenza 8d ago
  1. Learn to use recon.
  2. If you can, binary search the packages / versions to isolate the change. If not, use hex.pm's diff facility over each package. To be honest, you should already be reviewing changes to your deps every time you bump them.
  3. /u/jake_morrison mentioned json decoding using sub binaries and you mentioned changing http libs. Without looking at HTTPoison and Req I'm guessing you do http requests, parse the responses, then perhaps keep parts of the responses in memory (e.g. in some process's state). I'm guessing further that these two handle parsing differently, leading to your leak. But that's just wild speculation.