Skip to content

Version 2.2.x breaks Rails Actioncontroller:Live streaming #1619

@alor

Description

@alor

When you upgrade rack from 2.1.x to 2.2.x the streaming functionality in rails stops working.
A simple controller like this:

class MyController < ActionController::Base
  include ActionController::Live

  def index

    response.headers["X-Accel-Buffering"] = "no"
    response.headers['Content-Type'] = 'text/event-stream'

    5.times do |i|
      logger.info "stream"

      response.stream.write "hello #{i}\n"
      sleep 1
    end
  rescue ActionController::Live::ClientDisconnected => e
    # ignore client disconnections
    nil
  ensure
    response.stream.close
  end
  
end

will not stream anymore and will send all the data at the end of the cicle.
After many attempts I've pinned down that the culprit is Rack 2.2.x.

with version 2.2.0 if you invoke that controller will raise an exception:

#<NoMethodError: undefined method `reject' for nil:NilClass>
ruby-2.6.5@mod/gems/rack-2.2.0/lib/rack/request.rb:623:in `reject_trusted_ip_addresses'
ruby-2.6.5@mod/gems/rack-2.2.0/lib/rack/request.rb:363:in `ip'
ruby-2.6.5@mod/gems/actionpack-5.1.2/lib/action_dispatch/http/request.rb:250:in `ip'
ruby-2.6.5@mod/gems/railties-5.1.2/lib/rails/rack/logger.rb:51:in `started_request_message'
ruby-2.6.5@mod/gems/railties-5.1.2/lib/rails/rack/logger.rb:35:in `block in call_app'
ruby-2.6.5/lib/ruby/2.6.0/logger.rb:465:in `add'

with version 2.2.1 no exception is raised but the streaming does not work. same on version 2.2.2

I've tested it with Rails 5.1.x and 6.0.2.1 (the latest). Same behaviour.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions