Sławosz
Sławosz

Reputation: 11687

Is this ruby on rails code thread safe?

I have an issue with Logger in JRuby on Rails app. One thread changes log level to error and it does not change back. Is this code threadsafe, or should I look for other places where it is happening?

https://github.com/rails/rails/blob/master/activesupport/lib/active_support/benchmarkable.rb#L50

def silence
  message = "ActiveSupport::Benchmarkable#silence is deprecated. It will be removed from Rails 4.1."
  ActiveSupport::Deprecation.warn message
  old_logger_level, logger.level = logger.level, ::Logger::ERROR if logger
  yield
ensure
  logger.level = old_logger_level if logger
end

Upvotes: 2

Views: 515

Answers (2)

Rich Drummond
Rich Drummond

Reputation: 3509

I have encountered this very same thread safety problem with the Rails logger and JRuby. I don't know if you are looking for a workaround, but this fix worked for me: http://log.kares.org/2011/04/railslogger-is-not-threadsafe.html.

Upvotes: 2

Sławosz
Sławosz

Reputation: 11687

Ok, it looks like that during yield in first thread other thread will do silence it will have logger.level set to ERROR, so if other thread will end after first one, it will set level to ERROR permanently.

Upvotes: 3

Related Questions