rails/rails — Issue #3601: Yield in ERB or HAML partial loops and eats all memory in production
Author: nazar
Created: 2011-11-10 20:51:08+00:00
State: open

Hi all.

I've got a bug that's surfaced in production mode only (using rails 3.0.10 and haml 3.1.3 but also occurs when using the same logic in ERB).

```ruby
~$ uname -a
Linux 2.6.31-302-rs #7 SMP Thu Oct 29 22:57:03 UTC 2009 x86_64 GNU/Linux
~$ ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2011.03

```

I have a partial:

```ruby
- email.each do |msg|
=message_content_for_link(msg) do |content| #loops until all memory is consumed on the server in production
=link_to content, "#/email/#{msg.id}", :id => "message_#{msg.id}", :class => cycle('even', 'odd') + ' view_message'
```

message_content_for_link is a helper:

```ruby
def message_content_for_link(msg)
content = msg.is_read ? [content_tag(:span, '', :class => 'read')] : [content_tag(:span)]
content << content_tag(:p, h(msg.from), :class => 'from')
content << content_tag(:p, truncate(h(msg.subject)), :class => 'subject')

yield content.join('').html_safe
end
```

The above works fine in development mode. in production

```ruby
ActionView::Template::Error (failed to allocate memory) on the =message_content_for_link(msg) do |content| line
```

In production, the =message_content_for_link line keeps looping until all memory is exhausted.

Please note that this is not due to a large number of 'email' objects as the development version runs without issue using a far larger sample of objects than on a newly deployed production server with a few 'email' objects.

Please advise if I can provide any further information.

Thank you for your time.