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

SemanticLogger.reopen consumes 100% CPU #26

Closed
johnnncodes opened this issue Dec 10, 2016 · 6 comments
Closed

SemanticLogger.reopen consumes 100% CPU #26

johnnncodes opened this issue Dec 10, 2016 · 6 comments

Comments

@johnnncodes
Copy link

I experienced this issue: reidmorrison/semantic_logger#43 where semantic logger doesn't log anything on production that is using unicorn. I saw that I needed to do this:

# config/unicorn.conf.rb
after_fork do |server, worker|
  # Re-open appenders after forking the process
  SemanticLogger.reopen
end

# reference: http://rocketjob.github.io/semantic_logger/forking.html

to make it work.

But when I tried it, the site doesn't load and I found out it's because it is using 100% cpu after I added SemanticLogger.reopen

My config/environments/production.rb file also contains this:

config.rails_semantic_logger.add_file_appender = false # disable logging to a file
config.after_initialize do
  config.semantic_logger.add_appender(appender: :syslog, formatter: :json)
end
@johnnncodes
Copy link
Author

I tried to enable add_file_appender and disable logging to syslog:

config.rails_semantic_logger.add_file_appender = true 
config.after_initialize do
  # config.semantic_logger.add_appender(appender: :syslog, formatter: :json)
end

unicorn.rb:

# config/unicorn.conf.rb
after_fork do |server, worker|
  # Re-open appenders after forking the process
  SemanticLogger.reopen
end

I can see that it is now logging to the log file. But how can I make rails semantic logger to log to syslog when using unicorn?

@reidmorrison
Copy link
Owner

During a re-open it just calls the Ruby built-in Syslog capability as follows:

::Syslog.open(application, @options, @facility)

Suggest trying that code standalone and see if you can work out why Ruby or the the system syslog implementation is hanging when the process is forked.

@reidmorrison
Copy link
Owner

Please re-open the ticket with further information, or post questions in the gitter support channel if you are still experiencing difficulties.

@slinger987
Copy link

I too ran into this issue. I eventually traced it to the fact that the master will open the Syslog on the reopen method call. However, the same will be attempted with the workers, which appear to fail with

syslog already open (RuntimeError)

And I believe at this point, the workers are now stuck in an infinite loop attempting to start. I think the fix is to simply to check if Syslog is opened and only open if so, else do nothing.

@workgena
Copy link

workgena commented Dec 3, 2017

@slinger987 did you manage to resolve this issue?

syslog already open (RuntimeError)

@slinger987
Copy link

Yes, the code just needs to check to see if already opened.

i.e. Syslog.open unles Syslog.opened?

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

No branches or pull requests

4 participants