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

Warnings in app boot #122

Closed
kadru opened this issue Feb 15, 2021 · 2 comments
Closed

Warnings in app boot #122

kadru opened this issue Feb 15, 2021 · 2 comments

Comments

@kadru
Copy link

@kadru kadru commented Feb 15, 2021

Environment

  • Ruby 2.5.7
  • Rails 6.0.3.4
  • Semantic Logger 4.7.4
  • Rails Semantic Logger 4.5.0
  • Puma 5.1.1

config/application.rb

STDOUT.sync = true
config.rails_semantic_logger.processing = false
config.rails_semantic_logger.add_file_appender = false
config.rails_semantic_logger.format = :json
config.semantic_logger.add_appender(
  io: STDOUT,
  level: config.log_level,
  formatter: config.rails_semantic_logger.format)

config/puma.rb

on_worker_boot do
  # Re-open appenders after forking the process
  SemanticLogger.reopen
end

Expected Behavior

No warnings when is in use with rails and puma.

Actual Behavior

Warnings:

2021-02-15T02:37:25.152238+00:00 app[web.1]: [4] * Listening on http://0.0.0.0:14255
2021-02-15T02:37:25.152293+00:00 app[web.1]: [4] ! WARNING: Detected 2 Thread(s) started in app boot:
2021-02-15T02:37:25.152294+00:00 app[web.1]: [4] ! #<Thread:0x0000562c50117f88@/app/vendor/bundle/ruby/2.5.0/gems/semantic_logger-4.7.4/lib/semantic_logger/appender/async.rb:77 sleep_forever> - /app/vendor/bundle/ruby/2.5.0/gems/semantic_logger-4.7.4/lib/semantic_logger/appender/async.rb:150:in `pop'
2021-02-15T02:37:25.152352+00:00 app[web.1]: [4] ! #<Thread:0x0000562c51d23f88@/app/vendor/bundle/ruby/2.5.0/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:334 sleep> - /app/vendor/bundle/ruby/2.5.0/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:337:in `sleep'
@reidmorrison
Copy link
Owner

@reidmorrison reidmorrison commented May 3, 2021

We run Puma in single mode, so you are on your own with this one. The Semantic Logger thread being created is by design, without it no logging will be performed. Suggest looking into what is generating that warning log message, since it is not from Semantic Logger.

@reidmorrison
Copy link
Owner

@reidmorrison reidmorrison commented Jun 16, 2021

I booted our application in clustered mode without any issues. Below is the log output:

% bin/rails s
=> Booting Rails
=> Booting Puma
=> Rails 6.1.3.2 application starting in development 
=> Run `bin/rails server --help` for more startup options
...
[12175] Puma starting in cluster mode...
[12175] * Puma version: 5.3.2 (ruby 3.0.1-p64) ("Sweetnighter")
[12175] *  Min threads: 5
[12175] *  Max threads: 5
[12175] *  Environment: development
[12175] *   Master PID: 12175
[12175] *      Workers: 2
[12175] *     Restarts: (✔) hot (✔) phased
[12175] * Listening on http://127.0.0.1:3003
[12175] * Listening on http://[::1]:3003
[12175] Use Ctrl-C to stop
[12175] - Worker 0 (PID: 12186) booted in 0.01s, phase: 0
[12175] - Worker 1 (PID: 12187) booted in 0.01s, phase: 0
2021-06-16 20:22:04.182425 D [12186:puma threadpool 002 logger.rb:41] Rack -- Started -- { method: "GET", path: "/", ip: "127.0.0.1" }
...

As per the docs, just had to add SemanticLogger.reopen to the on_worker_boot to get logging working.

These are the lines I added / uncommented in config/puma.yml

workers ENV.fetch("WEB_CONCURRENCY") { 2 }

before_fork do
  ApplicationRecord.connection_pool.disconnect! if defined?(ActiveRecord)
end

on_worker_boot do
  ApplicationRecord.establish_connection if defined?(ActiveRecord)

  # Re-open appenders after forking the process
  SemanticLogger.reopen
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants