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.

Recent named_scope STI fix causes a massive slow down and memory leak

#5044

Commit 687d7f52c4a1d85666f1efc08ffa182e6dfeba57 (against 2-3-stable) from ticket #1570 named_scope not preserving proper model in STI is flawed and causes a massive slow down and memory leak. This caused my server to eat up all its RAM and swap before falling into a coma.

It's a fix to ensure that procs passed to named_scope are given the correct model when using STI. The "scoped" method uses a named_scope attached to ActiveRecord::Base so the self.model_name != parent_scope.model_name condition is always true in this case.

Here is a patch that checks to ensure self != Base but I'm wondering if this whole thing would still cause problems even when used in the right cases. Maybe the original commit should just be reverted?

Reported by James Le Cuirot · July 4th, 2010 @ 02:00 PM

State: resolved
Milestone: none
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. James Le Cuirot
    James Le Cuirot
    • Tag changed from activerecord 2-3-stable named_scope scoped memory leak patch to leak patch, 2-3-stable, activerecord, memory, named_scope, scoped

    July 4th, 2010 @ 02:55 PM

  2. James Le Cuirot
    James Le Cuirot
    • Tag changed from leak patch, 2-3-stable, activerecord, memory, named_scope, scoped to memory leak, 2-3-stable, activerecord, named_scope, patch, scoped

    July 4th, 2010 @ 02:56 PM

  3. José Valim
    José Valim
    • Importance changed from to Low

    Which ruby version are you using?

    July 4th, 2010 @ 02:57 PM

  4. James Le Cuirot
    James Le Cuirot

    1.8.7.

    (sorry, had a fight with the tagger)

    July 4th, 2010 @ 03:07 PM

  5. Repository
    Repository
    • State changed from new to resolved

    (from [bfbdeeae3080c89a0b27e42d684cbeb6206c6f60]) Use bind instead of instance_exec cause it may be causing memory leaks. Also, provide a simpler and sane implementation for scoped. [#5044 Recent named_scope STI fix causes a massive slow down and memory leak state:resolved] http://github.com/rails/rails/commit/bfbdeeae3080c89a0b27e42d684cbe...

    July 4th, 2010 @ 03:19 PM

  6. Logan Bowers