Hi, I'd like to discuss a few things regarding streaming support in
Rails and in Rack apps in general as well as suggesting a new Rails API
to better handle the integration between ActionController::Live and
Devise/Warden authentication failures.
I've detailed the subject in this project's README which suggests a new API:
https://github.com/rosenfeld/devise-and-streaming
I've also published that content in my site in case you'd prefer to
discuss it on Disqus:
http://rosenfeld.herokuapp.com/en/articles/ruby-rails/2016-07-02-the-sad-state-of-streaming-in-ruby-web-applications
Or we could discuss it in this thread as well.
Here is the TLDR version:
In order for Rails (or other Rack based solutions) to handle streaming
it has to spawn a new thread for the block requiring streaming.
Warden is a middleware that runs the next middleware in a
catch(:warden){} block and this is how it handles authentication failures.
Devise is probably the de facto authentication solution for Rails and
uses warden, so it faces the same issue:
https://github.com/plataformatec/devise/issues/2332
I'd like to propose Rails to add a new API that wouldn't process the
entire request with its filters in a spawn thread but only in the block
involving streaming, like this:
def my_action
# optionally call authenticate_user! here if it's not handled by a
before_action filter
chunked do |stream| # thread spawning would happen here
3.times{stream.write 'chunked text'; sleep 1}
end
end
This would allow the authentication part to work just fine.
There's also a broad discussion around Rack's design and future in that
README. I'd love to move that discussion forward if you agree the
situation should be improved.
Thanks for reading and considering my proposal,
Rodrigo.