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

Allow SyncProcessor to be called from appenders #282

Merged
merged 2 commits into from
Jun 27, 2024

Conversation

eagletmt
Copy link
Contributor

SyncProcessor#log could be called recursively from an appender like Bugsnag and Sentry.

Issue # (if available)

#281

Changelog

Allow SyncProcessor to be called from appenders

Description of changes

SyncProcessor#log could be called recursively from an appender like Bugsnag and Sentry. However, SyncProcessor doesn't allow it because it uses Mutex to protect SyncProcessor#log. Here are code snippets to reproduce the Mutex error.

require 'semantic_logger/sync'
require 'sentry-ruby'

SemanticLogger.add_appender(appender: :sentry_ruby)

Sentry.init do |config|
  config.logger = SemanticLogger[Sentry]
  config.background_worker_threads = 0
  config.dsn = 'http://foo@localhost/bar'
end

logger = SemanticLogger['MyClass']
begin
  raise 'something went wrong'
rescue => e
  logger.error('oops', e)
end
require 'semantic_logger/sync'
require 'bugsnag'

ENV['BUGSNAG_API_KEY'] = '0123456789abcdef0123456789abcdef'

SemanticLogger.add_appender(appender: :bugsnag)

logger = SemanticLogger['MyClass']
begin
  raise 'something went wrong'
rescue => e
  logger.error('oops', e)
end

This PR resolves the issue by replacing Mutex with Monitor. Monitor allows to enter the critical section if the Mutex's owner is the current thread.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

eagletmt and others added 2 commits June 18, 2024 21:56
SyncProcessor#log could be called recursively from an appender like
Bugsnag and Sentry.
@reidmorrison reidmorrison merged commit b80407e into reidmorrison:master Jun 27, 2024
5 checks passed
@eagletmt eagletmt deleted the recursive-lock branch December 31, 2024 09:55
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

Successfully merging this pull request may close these issues.

2 participants