Memory leak in update from 2.1.2 to 2.2.2


#1

My last deployment was based on Rails 2.1.2 and would run for months
without restarts and without leaking memory; memory would sit at
around 35 to 40M per Mongrel instance.

On updating to 2.2.2 I’m seeing gradual memory bloat and every few
days it hits its resource limit (130M per Mongrel) and monit does a
restart.

I don’t think it’s a change in my own code that introduced the leak,
seeing as I made only minimal changes necessary to fix breakage caused
by updating Rails:

$ git diff 3f39f3a…5fc7345 --stat – app config lib
app/controllers/application.rb | 26 ±----
app/controllers/comments_controller.rb | 4 ±
app/helpers/application_helper.rb | 10 +++
app/helpers/articles_helper.rb | 6 –
app/models/user.rb | 4 ±
app/views/articles/edit.html.haml | 2 ±
app/views/articles/new.html.haml | 2 ±
app/views/articles/show.html.haml | 2 ±
app/views/comments/edit.html.haml | 2 ±
app/views/issues/_issues.html.haml | 2 ±
app/views/search/_article.html.haml | 2 ±
app/views/search/_issue.html.haml | 2 ±
app/views/search/_post.html.haml | 2 ±
app/views/search/_topic.html.haml | 2 ±
config/boot.rb | 4 ±
config/deploy.rb | 3 ±
config/environment.rb | 14 ±–
config/environments/development.rb | 2 -
config/environments/production.rb | 2 -
config/environments/test.rb | 8 ±-
config/initializers/extensions.rb | 17 ++++
config/locales/en.yml | 5 +
lib/active_record/acts/classifiable.rb | 2 ±
lib/active_record/acts/searchable.rb | 2 ±
lib/sortable.rb | 2 ±
lib/tasks/rspec.rake | 132 ++++++++++++++++++++++++
++++++++
26 files changed, 194 insertions(+), 67 deletions(-)

So I’m trying to hunt down the source of the leak, but it’s kind of
intimidating because it’s almost certainly a change in “vendor”, which
churned a whole lot from 2.1.2 to 2.2.2:

1313 files changed, 105152 insertions(+), 63806 deletions(-)

Wondering if anyone else has seen memory leaks creep in while moving
from 2.1.2 to 2.2.2?

Cheers,
Wincent


#2

On 12 Jan 2009, at 10:42, Wincent C. wrote:

My last deployment was based on Rails 2.1.2 and would run for months
without restarts and without leaking memory; memory would sit at
around 35 to 40M per Mongrel instance.

On updating to 2.2.2 I’m seeing gradual memory bloat and every few
days it hits its resource limit (130M per Mongrel) and monit does a
restart.

I know of two memory leaks in 2.2.2:

http://github.com/rails/rails/commit/9f69ff12d44c4d1e475fd6efede120ccedba3b3e
http://github.com/rails/rails/commit/5ede4ce188d29aef94af78f27d89169ac4ee54cd

Fred


#3

On 12 ene, 11:55, Frederick C. removed_email_address@domain.invalid wrote:

I know of two memory leaks in 2.2.2:

http://github.com/rails/rails/commit/9f69ff12d44c4d1e475fd6efede120cc...http://github.com/rails/rails/commit/5ede4ce188d29aef94af78f27d89169a

Thanks a lot, Fred.

I’ll try applying both of those fixes before I go any further,
although I suspect they aren’t the cause of the bloat I’m seeing (both
of the pieces of code which got patched pre-date 2.1.2 and are
relatively old, one from August 2008 and one from 2006, and I didn’t
really see any memory bloat in 2.1.2).

Cheers,
Wincent


#4

We had similar problem after upgrading from 2.1.0 to 2.2.2. Rails just
kept accumulating memory. After we applied the buffered logger fix
(http://github.com/rails/rails/commit/
9f69ff12d44c4d1e475fd6efede120ccedba3b3e) we were back normal memory
usage, no leaks.


#5

Ran into a similar problem as well. After a frustrating week basically
unpacking all gems, and rebuilding our gem list fixed it (which is a
terrible answer cause i can’t rightly say what caused the leak). Best
i can tell there was some issue with different gems that caused a
memory leak and removing and reinstalling them all seemed to resolve
it. Note to self, always check gems into your project