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]
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:
Root cause
Sentry::BackgroundWorkerusesConcurrent::ThreadPoolExecutor. On CRuby, concurrent-ruby protects that executor with::Mutex; a fiber-aware replacement can scheduleFiber#resumewhile the worker crosses thread/fiber execution contexts. em-synchrony's mutex unlock path resumes its next waiter throughEM.next_tick, which matches the observed stack.Stock em-synchrony exposes
EM::Synchrony::Thread::Mutexseparately rather than globally replacing::Mutex; this occurs in applications or dependencies that apply that replacement.Reproduction conditions
Thread::Mutex/::Mutexis replaced with a fiber-aware implementationSentry.capture_exceptioncalled from the EventMachine processWorkaround
Set
config.background_worker_threads = 0for affected processes. This usesConcurrent::ImmediateExecutorand sends from the calling execution context.Related: #2596 tracks broader concurrent-ruby and thread integration work.
Requested by Simon Zhong.
--
View Junior Session [Sentry]