bugsnag / bugsnag-ruby

BugSnag error monitoring & reporting software for rails, sinatra, rack and ruby
https://docs.bugsnag.com/platforms/ruby
MIT License
249 stars 174 forks source link

[thread_queue] Uncaught exception not delivered when Bugsnag.notify was previously called. #727

Open alx75 opened 2 years ago

alx75 commented 2 years ago

Describe the bug

Uncaught exception from a ruby script is not notified to bugsnag when:

Steps to reproduce

Configure Bugsnag with delivery method to thread_queue

Run: Bugsnag.notify('This is notified correctly') raise 'This is not notified with thread_queue'

Environment

My understanding of the issue

Bugsnag::Delivery::ThreadQueue registers a at_exit to finish processing all notifications from the queue and then stop the thread that dequeue the notifications. Bugsnag register a at_exit hook to deliver the unhandled error to Bugsnag::Delivery::ThreadQueue

This doesn't work when a notification was first sent with Bugsnag.notify because afterward, raising an unhandled error will be processed by Bugsnag at_exit however Bugsnag::Delivery::ThreadQueue at_exit was already processed.

yousif-bugsnag commented 2 years ago

Hi @alx75 , thanks for reporting this. I've been able to reproduce the issue - we're going to take a look as soon as priorities allow.

alx75 commented 2 years ago

Ok thanks. Easy workaround is to use synchronous delivery mode for scripts.

johnkiely1 commented 2 years ago

Hi @alx75 . Just a quick update, this does seem to be an issue for Ruby scripts that aren't running in a webserver. We're looking to fix it in the next major version release, for now using the synchronous delivery looks like a good option as a workaround. We will update again once that has been released.