-
Notifications
You must be signed in to change notification settings - Fork 205
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
Prevent ConcurrentModificationException in Before notify/breadcrumb callbacks #266
Conversation
Pull Request Test Coverage Report for Build 1182
💛 - Coveralls |
public boolean run(Error error) { | ||
beforeNotifyTasks.add(new BeforeNotifySkeleton()); | ||
// modify the Set, when iterating to the next callback this should not crash | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test fails without the change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, as it would modify the contents of the LinkedHashSet
when an iterator has already been implicitly created in runBeforeNotifyTasks
If a callback is added while existing callbacks are being iterated through, bugsnag will crash. This changeset addresses this issue by using a ConcurrentLinkedQueue which retains the callback order, but will not crash if new callbacks are added concurrently. This fix has been ported from bugsnag/bugsnag-android#266
Avoid eager initialization of bugsnag tasks
Prevents a
ConcurrentModificationException
from occurring in theBeforeNotify
andBeforeRecordBreadcrumb
callbacks, if an element is added to the collection during or at the same time asnotify
is called.A
ConcurrentLinkedQueue
is used in place of aLinkedHashSet
as this retains the order of the callbacks. There's a bit of a tradeoff here with #127 - I've added a check to the client method to avoid adding duplicate callbacks, and assumed that anyone adding to the Collection directly knows what they're doing.