You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classStreamingTestController < ApplicationControllerincludeActionController::Livedefindex# This header doesn't seem to be necessary, but it's probably good to set it.response.headers['Content-Type']='text/event-stream'# These two headers are requried to work around a mismatch of expectations between# rack 2.2.x and rails. https://github.com/rack/rack/issues/1619response.headers['Last-Modified']=Time.now.httpdateresponse.headers['ETag']='0'5.timesdoresponse.stream.write"hello world\n"sleep1endensureresponse.stream.closeendend
When you curl that endpoint you should see one instance of hello world output immediately, then a one second pause, and then another, and so on until you see five instances.
curl http://localhost:3001/streaming_test/index
hello world
hello world
hello world
hello world
hello world
When a version of active_model_serializers from the 0.9.x branch is loaded, instead of getting a streaming response you'll see nothing for about 5 seconds, then you'll see 5 instances of hello world output all at once.
With the 0.10.x branch the problem no longer happens.
I'm opening this issue mostly for documentation purposes so that if someone else discovers that streaming isn't working in their app they might stumble across this issue and save some time.
Steps to reproduce
Generate a new rails app
Make a streaming controller like the one above
curl it to see that it streams
Add gem "active_model_serializers", "0.9.8" to the Gemfile
bundle install
curl the endpoint again to see that streaming is no longer working
Integrated application and version (e.g., Rails, Grape, etc): rails 5.2.8
Backtrace
None
Additonal helpful information
Here's a repo that demonstrates the problem with the 0.9.x line. The README describes how to alter the Gemfile to see that the 0.10.x line fixes the issue.
Expected behavior vs actual behavior
Consider a simple streaming example like this:
When you
curl
that endpoint you should see one instance ofhello world
output immediately, then a one second pause, and then another, and so on until you see five instances.When a version of
active_model_serializers
from the0.9.x
branch is loaded, instead of getting a streaming response you'll see nothing for about 5 seconds, then you'll see 5 instances ofhello world
output all at once.With the
0.10.x
branch the problem no longer happens.I'm opening this issue mostly for documentation purposes so that if someone else discovers that streaming isn't working in their app they might stumble across this issue and save some time.
Steps to reproduce
curl
it to see that it streamsgem "active_model_serializers", "0.9.8"
to theGemfile
bundle install
curl
the endpoint again to see that streaming is no longer workingEnvironment
ActiveModelSerializers Version:
0.9.3
&0.9.8
Output of
ruby -e "puts RUBY_DESCRIPTION"
: ruby 2.6.8p205 (2021-07-07 revision 67951) [x86_64-darwin20]OS Type & Version: macOS 12.3
Integrated application and version (e.g., Rails, Grape, etc): rails
5.2.8
Backtrace
None
Additonal helpful information
Here's a repo that demonstrates the problem with the
0.9.x
line. TheREADME
describes how to alter theGemfile
to see that the0.10.x
line fixes the issue.https://github.com/Octo-Labs/rails_streaming_test
The text was updated successfully, but these errors were encountered: