Skip to content

Background worker fails with fiber-aware mutexes #3052

Description

@sentry-junior

Processes that replace Ruby's mutex implementation with a fiber-aware mutex can fail when Sentry dispatches an event through its default background worker. The failure prevents the event from being sent and logs:

FiberError: attempt to resume a transferring fiber
em-synchrony (1.0.6) lib/em-synchrony/thread.rb:56:in `resume'
em-synchrony (1.0.6) lib/em-synchrony/thread.rb:56:in `block in unlock'

Root cause

Sentry::BackgroundWorker uses Concurrent::ThreadPoolExecutor. On CRuby, concurrent-ruby protects that executor with ::Mutex; a fiber-aware replacement can schedule Fiber#resume while the worker crosses thread/fiber execution contexts. em-synchrony's mutex unlock path resumes its next waiter through EM.next_tick, which matches the observed stack.

Stock em-synchrony exposes EM::Synchrony::Thread::Mutex separately rather than globally replacing ::Mutex; this occurs in applications or dependencies that apply that replacement.

Reproduction conditions

  • EventMachine with em-synchrony 1.0.6
  • A process where Thread::Mutex / ::Mutex is replaced with a fiber-aware implementation
  • Sentry's default background worker enabled
  • Sentry.capture_exception called from the EventMachine process

Workaround

Set config.background_worker_threads = 0 for affected processes. This uses Concurrent::ImmediateExecutor and sends from the calling execution context.

Related: #2596 tracks broader concurrent-ruby and thread integration work.

Requested by Simon Zhong.

--

View Junior Session [Sentry]

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions