Skip to content

Requesting backport to 8.0 for a streaming bugfix only present in 8.1 (#51508) #54814

@jarthod

Description

@jarthod

Hello, as discussed in #52094, one change in 8.0 broke streaming compatibility when upgrading from 7.2.

I've been using streaming in rails since 2015 with https://github.com/jarthod/render-later and after the 7.2 to 8.0.1 update I started getting this exception on my streaming pages:

curl http://localhost:3000
Puma caught this error: undefined method `call' for nil (NoMethodError)
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/actionview-8.0.1/lib/action_view/renderer/streaming_template_renderer.rb:23:in `rescue in each'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/actionview-8.0.1/lib/action_view/renderer/streaming_template_renderer.rb:19:in `each'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/actionpack-8.0.1/lib/action_dispatch/http/response.rb:111:in `to_ary'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/actionpack-8.0.1/lib/action_dispatch/http/response.rb:523:in `to_ary'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/rack-3.1.10/lib/rack/body_proxy.rb:51:in `method_missing'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/rack-3.1.10/lib/rack/body_proxy.rb:51:in `method_missing'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/rack-3.1.10/lib/rack/body_proxy.rb:51:in `method_missing'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/rack-3.1.10/lib/rack/body_proxy.rb:51:in `method_missing'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/puma-6.6.0/lib/puma/request.rb:187:in `prepare_response'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/puma-6.6.0/lib/puma/request.rb:132:in `handle_request'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/puma-6.6.0/lib/puma/server.rb:472:in `process_client'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/puma-6.6.0/lib/puma/server.rb:254:in `block in run'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/puma-6.6.0/lib/puma/thread_pool.rb:167:in `block in spawn_thread'

I tried removing all my Rack streaming specific patches and disabling all my middlewares of course but it didn't change much. I was already on Rack 3.1 so this is not linked to the rack 2 → 3 upgrade, which I already did a while back.

The good news is that this has already been fixed in Rails main (8.1.0-alpha at time of writing). According to @ioquatix the fix was made in #51508

So I would like to suggest this fix be backported to 8.0.2+. It's not a big deal for me (I can easily wait and skip 8.0) but to avoid breaking streaming for every people using streaming and upgrading to 8.0 between 7.2 and 8.1.

Thanks 🙇

Steps to reproduce

The problem can easily be reproduced from the small dummy test rails app I created in https://github.com/jarthod/render-later repo for automated testing:

cd test/dummy
bundle install --gemfile=../gemfiles/rails-8.0
bundle exec --gemfile=../gemfiles/rails-8.0 rails s
# in another terminal:
curl http://localhost:3000
# same error shown above 

Expected behavior

curl http://localhost:3000
[...]
</script><script>rl_insert('rl-srv-1', '\n          UP · 99.0%\n');
</script><script>rl_insert('rl-srv-2', '\n          UP · 99.1%\n');
</script><script>rl_insert('rl-srv-3', '\n          UP · 99.2%\n');
</script><script>rl_insert('rl-srv-4', '\n          UP · 99.3%\n');
</script><script>rl_insert('rl-srv-5', '\n          UP · 99.4%\n');
</script><script>rl_insert('rl-srv-6', '\n          UP · 99.5%\n');
</script><script>rl_insert('rl-srv-7', '\n          UP · 99.6%\n');
</script><script>rl_insert('rl-srv-8', '\n          UP · 99.7%\n');
</script><script>rl_insert('rl-srv-9', '\n          UP · 99.8%\n');
</script><script>rl_insert('rl-srv-10', '\n          UP · 99.9%\n');
</script>
  </body>
</html>

Actual behavior

curl http://localhost:3000
Puma caught this error: undefined method `call' for nil (NoMethodError)
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/actionview-8.0.1/lib/action_view/renderer/streaming_template_renderer.rb:23:in `rescue in each'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/actionview-8.0.1/lib/action_view/renderer/streaming_template_renderer.rb:19:in `each'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/actionpack-8.0.1/lib/action_dispatch/http/response.rb:111:in `to_ary'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/actionpack-8.0.1/lib/action_dispatch/http/response.rb:523:in `to_ary'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/rack-3.1.10/lib/rack/body_proxy.rb:51:in `method_missing'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/rack-3.1.10/lib/rack/body_proxy.rb:51:in `method_missing'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/rack-3.1.10/lib/rack/body_proxy.rb:51:in `method_missing'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/rack-3.1.10/lib/rack/body_proxy.rb:51:in `method_missing'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/puma-6.6.0/lib/puma/request.rb:187:in `prepare_response'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/puma-6.6.0/lib/puma/request.rb:132:in `handle_request'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/puma-6.6.0/lib/puma/server.rb:472:in `process_client'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/puma-6.6.0/lib/puma/server.rb:254:in `block in run'
/home/bigbourin/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/puma-6.6.0/lib/puma/thread_pool.rb:167:in `block in spawn_thread'

Here is my test matrix showing the failures on Rails 8.0.1 only: https://github.com/jarthod/render-later/actions/runs/13290274804/job/37109071845 (it's not easy to see the exception here though after capybara, that's why I show the simpler manual curl test above)

System configuration

Rails version:
7.2.2.1 (for the working version)
8.0.0, 8.0.1, 8.0.2 (for the broken versions)

Ruby version:
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [x86_64-linux]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions