airbrake / airbrake-ruby

A plain Ruby Airbrake notifier
https://airbrake.io
MIT License
79 stars 67 forks source link

ThreadError: can't move to the enclosed thread group #576

Closed alexpapworth closed 4 years ago

alexpapworth commented 4 years ago

Hello. I've got an error when calling Airbrake.notify within a fork.

Received exception when reporting failure: #<ThreadError: can't move to the enclosed thread group>
/gems/ruby-2.3.8/gems/airbrake-ruby-4.14.0/lib/airbrake-ruby/thread_pool.rb:121:in `add'
/gems/ruby-2.3.8/gems/airbrake-ruby-4.14.0/lib/airbrake-ruby/thread_pool.rb:121:in `block in spawn_workers'
/gems/ruby-2.3.8/gems/airbrake-ruby-4.14.0/lib/airbrake-ruby/thread_pool.rb:121:in `times'
/gems/ruby-2.3.8/gems/airbrake-ruby-4.14.0/lib/airbrake-ruby/thread_pool.rb:121:in `spawn_workers'
/gems/ruby-2.3.8/gems/airbrake-ruby-4.14.0/lib/airbrake-ruby/thread_pool.rb:86:in `block in has_workers?'
/gems/ruby-2.3.8/gems/airbrake-ruby-4.14.0/lib/airbrake-ruby/thread_pool.rb:81:in `synchronize'
/gems/ruby-2.3.8/gems/airbrake-ruby-4.14.0/lib/airbrake-ruby/thread_pool.rb:81:in `has_workers?'
/gems/ruby-2.3.8/gems/airbrake-ruby-4.14.0/lib/airbrake-ruby/async_sender.rb:41:in `has_workers?'
/gems/ruby-2.3.8/gems/airbrake-ruby-4.14.0/lib/airbrake-ruby/notice_notifier.rb:122:in `default_sender'
/gems/ruby-2.3.8/gems/airbrake-ruby-4.14.0/lib/airbrake-ruby/notice_notifier.rb:36:in `notify'
/gems/ruby-2.3.8/gems/airbrake-ruby-4.14.0/lib/airbrake-ruby.rb:169:in `notify'

I notice a similar discussion in #312, but the @mutex.synchronize block in def has_workers? doesn't seem to be working for me.

Any ideas on how to fix this?

kyrylo commented 4 years ago

Hi, thanks for the report. Can you reproduce that reliably? I have an idea for the fix but it would be really nice to confirm it to be 100% sure.

alexpapworth commented 4 years ago

Alright, that happens as part of my test suite when running on Jenkins. It fails there 100% of the time, so I’m happy to test out some code you have to see if that works.

Unfortunately the error is embedded a few files deep, so let me see if I can extract the key components into a smaller script that also fails reliably.

alexpapworth commented 4 years ago

Spent some time trying to extract a smaller test script, but wasn't able to.

The issue is still happening 100% of the time, so I'll be able to test any code you have against my codebase.

kyrylo commented 4 years ago

Thanks a lot! It's really helpful that you can repro that in 100% of cases. I will publish my guess as a PR and we will test it against your app.

kyrylo commented 4 years ago

I managed to find a repro case and came up with https://github.com/airbrake/airbrake-ruby/pull/577

Can you please give it a try?

alexpapworth commented 4 years ago

Just ran my test using the new branch three times (to be sure). No ThreadError errors!

That's a big thumbs up from me!

kyrylo commented 4 years ago

Awesome, thanks a lot!

kyrylo commented 4 years ago

I released this fix in v4.14.1.