-
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 Bugsnag.init from instantiating more than one client #403
Conversation
} | ||
|
||
val futures = threadPool.invokeAll(callables) | ||
val uniqueClients = futures.map { it.get() }.distinct() |
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 blocks until all the Callables
have finished execution, then gets the returned Client
objects and removes any duplicates from the Collection (there should only ever be 1 item in this list).
I've addressed all outstanding feedback and have reduced duplication in the |
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.
LGTM.
Tested manually and I see the log message when multiple init()
calls are made. Error reporting still works.
Goal
If
Bugsnag.init
is called multiple times, multipleClient
objects will be instantiated. This is generally not the desired behaviour, could lead to undesired side-effects, and is also a very expensive operation (approx 100ms for each initialisation on a test device).For a real world example, if
Bugsnag.init
is called from withinonCreate
in anActivity
rather than anApplication
subclass, it's possible that multiple clients could be instantiated over the app's lifecycle.This changeset alters
Bugsnag.init
so that it will only instantiate aClient
if one hasn't been created already. For exceptional cases where a user needs to instantiate multipleClient
objects, it remains possible to do so by invoking theClient
constructor directly.Changeset
Bugsnag.init
methods, so that only one thread can attempt initialisation at a time.Client
object if the existing field is null, and otherwise return the existing instance.Tests
Bugsnag.init
calls, and verified that a warning was logged.Bugsnag.init
on multiple threads, and verifies only one client was created.