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

Warning: Detected 21 Thread(s) started in app boot on Rails 5rc1 #991

Closed
mathie opened this issue Jun 3, 2016 · 9 comments
Closed

Warning: Detected 21 Thread(s) started in app boot on Rails 5rc1 #991

mathie opened this issue Jun 3, 2016 · 9 comments

Comments

@mathie
Copy link

mathie commented Jun 3, 2016

Hi,

I'm just spinning up a brand new Rails 5 project to try it out. It comes with puma by default (which is awesome, and saves me installing it later!). Straight out of the box, it works fine. Then I follow the Heroku guidelines for configuring it, which essentially to uncomment the following lines in config/puma.rb:

workers ENV.fetch("WEB_CONCURRENCY") { 2 }
preload_app!
on_worker_boot do
  ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
end

Now when I boot the server, I get:

[15663] Puma starting in cluster mode...
[15663] * Version 3.4.0 (ruby 2.3.1-p112), codename: Owl Bowl Brawl
[15663] * Min threads: 5, max threads: 5
[15663] * Environment: development
[15663] * Process workers: 2
[15663] * Preloading application
[15663] * Listening on tcp://0.0.0.0:3000
[15663] ! WARNING: Detected 21 Thread(s) started in app boot:
[15663] ! #<Thread:0x007fe40cd38040@/Users/mathie/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/listen-3.0.8/lib/listen/internals/thread_pool.rb:6 sleep> - /Users/mathie/.rbenv/versions/2.3.1/lib/ruby/ge
ms/2.3.0/gems/rb-fsevent-0.9.7/lib/rb-fsevent/fsevent.rb:42:in `select'
[ ... repeated, presumably ~20 more times ...]
[15663] Use Ctrl-C to stop
[15663] - Worker 1 (pid: 15707) booted, phase: 0
[15663] - Worker 0 (pid: 15706) booted, phase: 0

The bit that bothers me is the warning about multiple threads, in case that wasn't clear.

If I were to hazard a guess, I'd say whatever's new in Rails 5 that has introduced the dependency on listen is responsible for this, but I don't know what that is. I also don't know if it needs its threads restarted on_worker_boot or whether Rails handles that correctly, automatically. It would be ace if, between you and the Rails team, you could figure out how to elide the warning. I don't like ignoring warnings!

Having written this up, I suspect I should be submitting an issue to the Rails repo instead, but since it's now such little effort to do so, I'm going to flag it up here, too. 😄

@mathie
Copy link
Author

mathie commented Jun 3, 2016

OK, so I've now submitted a strikingly similar issue over at the Rails repo rails/rails#25259 since I'm not sure who's best placed to deal with it!

@evanphx
Copy link
Member

evanphx commented Jun 3, 2016

@mathie could you gist the whole output, I want to see if the output is REALLY the same thing 21 times...

@mathie
Copy link
Author

mathie commented Jun 3, 2016

Good call, there are a couple of exceptions: https://gist.github.com/mathie/28347310c600e0396568a79c61486099 Most are in select() somewhere in fsevent, but a couple are sleep()ing in listen.

Sorry, just to be a pain in the ass, this isn't exactly the same codebase as it was this morning -- I've been hacking on it all day -- and we're up to 25 mysterious threads now. 😄

@evanphx
Copy link
Member

evanphx commented Jun 3, 2016

Hey @schneems, weren't you looking into rails s not managing listen threads properly perhaps? This looks very similar.

@mathie: Are you starting puma via rails s or puma?

@schneems
Copy link
Contributor

schneems commented Jun 3, 2016

Yes over at rails/rails#24990 (comment)

The issue is that the Listen gem boots before the puma forks boot, so puma gives that warning. It's loosely related to a problem that i'm working on i.e. if we weren't booting before the workers get spawned then there wouldn't be an issue or a warning. I don't know if we'll be able to do that.

I would say yes this is definitely under the rails/rails umbrella of things to worry about and not Puma, also this warning isn't something to be immediately concerned with right now. However you might want to subscribe to that linked thread

@mathie
Copy link
Author

mathie commented Jun 5, 2016

@evanphx I'm starting puma with bundle exec puma -C config/puma.rb -p ${PORT} (via foreman). The puma configuration is here: https://gist.github.com/mathie/9967bf0bf000b7fe27dbea94df734954 and it's just the stock configuration that's generated by Rails, except that I've uncommented workers, preload_app! and on_worker_boot as the comments indicate.

If I start it with rails s it doesn't show the warnings, but I suspect that's just because it's not honouring the configuration file at all? (Which strikes me as a bug in Rails, right?)

This whole conversation should probably be going over to rails/rails. It's perhaps worth noting, though, that code reloading definitely isn't working for me with workers enabled.

@mathie
Copy link
Author

mathie commented Jun 5, 2016

Scratch that thought: running rails s does honour the configuration file. But it doesn't show the warnings.

@mathie
Copy link
Author

mathie commented Jun 5, 2016

In either case, code reloading (in development) works OK in single mode, but not in clustered mode...

@schneems
Copy link
Contributor

schneems commented Jun 5, 2016

Not a puma issue at all. Let's close this thread.

@evanphx evanphx closed this as completed Jul 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants