ruby.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
If you are interested in the Ruby programming language, come join us! Tell us about yourself when signing up. If you just want to join Mastodon, another server will be a better place for you.

Administered by:

Server stats:

1.1K
active users

Anyone have pointers for visualizing heap dumps? I am looking for a memory leak in our production app and I am having a heck of a time even finding a good suspect to start looking into.

Steven Harman

I found reap, “A tool for parsing heap dumps by analyzing the reference graph," and was able to generate some flame graphs from that. Here's a graph of a worker that was leaking memory. Only 2-3 of 12 on the machine were leaking at the time. The others looked “normal."

Now to figure out what a "normal" flame graph looks like for our app. And why the heck that Thread, and subsequent ActiveSupport::Notification::Event are holding 1.75GiB of memory.

The flame graph revealed a thread (:rimshot:) to tug on. It turns out, ActiveSupport::Notifications.subscribe blocks can leak AS::N::Event objects in Rails < 7.1 if an exception is raised while processing the Event. I spotted it in one of our flame graphs from a leaking Puma worker in production. I then used sheap to interrogate the leaked Event, and figure out what sort of initial request was causing it to leak. The fix had coincidentally been fixed in a dependency. (1/2)

The error-raising dependency problem was a recent change that caused invalid URLs to raise an error while trying to “clean" them. github.com/bugsnag/bugsnag-rub

Up in -land, the underlying place where the Event objects were being leaked was fully removed in Rails 7.1. So, yay! And thanks @jhawthorn! github.com/rails/rails/pull/43

Phew! What a trip.

GitHubFix unhandled `URI::InvalidURIError` in `Cleaner#clean_url` by imjoehaines · Pull Request #811 · bugsnag/bugsnag-rubyBy imjoehaines

@stevenharman oh man, that reminds me of a time that I tried to use AS::N for a generic pub/sub mechanism within an app.

One thing I learned is that exceptions were silently swallowed, and that overall it was just a Bad Idea. I unrolled that design decision in fairly short order.

The behavior may be different today, but I will stake the position that it’s not a good idea to use it like that. It’s not what it’s for, even though it can look like it when you squint a little.