Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

MASSIVE memory leak in AssetTag

#1419

Every time you use a asset tag helper referencing a new asset url, references to the controller/template objects are stored in the AssetTag::Cache and never released.

If you render thousands of 3rd party images on your site, each image_tag call creates a hard reference in the AssetTag::Cache, which in turn references the controller/template, not allowing anything created in that request to leave scope, hence you have a massive memory leak.

The objects are cached b/c of filesystem access to determine the modified source string. E.g. "foo" -> "/stylesheets/foo.css"

The attached patch solves the issue by caching only the modified source strings, which is similar to the previous implementation, with a further optimization of caching only asset paths that are relative.

Reported by aaronbatalion · November 19th, 2008 @ 07:07 PM

State: resolved
Milestone: none
Assigned to: josh josh
Importance: none

Activity

  1. Jeremy Kemper
    Jeremy Kemper
    • State changed from new to open
    • Assigned user set to josh
    • Milestone cleared.

    November 19th, 2008 @ 07:14 PM

  2. Michael Koziarski
    Michael Koziarski

    Change looks good to me, josh?

    November 19th, 2008 @ 07:17 PM

  3. aaronbatalion
    aaronbatalion

    Wrote a quick blog post explaining the issue in more detail. http://blog.hungrymachine.com/20...

    Also, I believe AssetTagCollection has the same problem, and isnt covered in my patch.

    November 19th, 2008 @ 09:11 PM

  4. aaronbatalion
    aaronbatalion

    Attached is an updated patch that accounts for the assettag type being included in the cache key. Including the name of the class is better than self itself, against for hard references.

    Also added a failing test that now passes.

    November 19th, 2008 @ 11:15 PM

  5. josh
    josh

    ah, I hate this cache. I should def look into preloading the asset folder contents on boot.

    November 19th, 2008 @ 11:22 PM

  6. Repository
    Repository
    • State changed from open to resolved

    (from [24dbd4b9581ba2affef9e8e96570200ee1e3266c]) Fixed asset host to not cache objects [#1419 MASSIVE memory leak in AssetTag state:resolved]

    Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...

    November 19th, 2008 @ 11:29 PM

  7. Repository
    Repository

    (from [d7f4921a9a852da7c1075275eaf73822edb7acff]) Fixed asset host to not cache objects [#1419 MASSIVE memory leak in AssetTag state:resolved]

    Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...

    November 19th, 2008 @ 11:29 PM

  8. aaronbatalion
    aaronbatalion

    Josh, Please commit the 2nd patch. I found a bug that will mix js/css files and cache them as the same keys. This bug is still open.

    November 19th, 2008 @ 11:35 PM

  9. aaronbatalion
  10. Jeremy Kemper