Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing an ActionController::Live controller leads to a deadlock #31813

Closed
Kjir opened this issue Jan 28, 2018 · 2 comments · Fixed by #41609
Closed

Testing an ActionController::Live controller leads to a deadlock #31813

Kjir opened this issue Jan 28, 2018 · 2 comments · Fixed by #41609
Labels

Comments

@Kjir
Copy link

Kjir commented Jan 28, 2018

This is a deeper and more correct report of #31200 after some deep investigation of the issue.

Steps to reproduce

In a new rails application generate a controller and implement it like follows:

rails new stream_test
cd stream_test
bin/rails g controller Home index
class HomeController < ApplicationController
  include ActionController::Live

  def index
    11.times { response.stream.write('a') }
    ensure
      response.stream.close
  end
end

Then run the controller test

bin/rails test

Expected behavior

The test should succeed

Actual behavior

The test will just hang forever. This is because under the hood when streaming responses with ActionController::Live we are adding the responses to a SizedQueue with size 10. In a real context, the browser will consume the data as soon as it is generated thus freeing space in the queue; in a rack test context, however, we are expecting the whole response to be returned without actually consuming it as it is processed. So if the test includes more than 10 writes on the stream, the tests will hang forever.

I can see three possible solutions:

  • Disable streaming in test environments
  • Substitute the SizedQueue with an infinite Queue in test environments
  • Consume the response in async.

The third option is arguably the best solution, but it is also the most complex one. I'm also not sure where it should be implemented, it could require changes in the rack-test gem.

Any other thoughts?

System configuration

Rails version:
Lastest master (Rails 5.2.0.beta2) at the time of writing. Commit: a88eb9087260cca256c6faba40bf538d4a0289b3
Ruby version:
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin16]

@rails-bot
Copy link

rails-bot bot commented Apr 29, 2018

This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 5-1-stable branch or on master, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.

@zzak
Copy link
Member

zzak commented Jun 24, 2021

Fixed by #41609

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants