fix: Cleaning up FirebaseApp state management #476
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We have a mechanism in place to tear down any SDK state and managed resources upon calling
FirebaseApp.delete()
. However the way this is used and enforced across services is inconsistent at the moment:FirebaseAuth
uses some complex and repetitive logic to throw errors from all methods afterdelete()
has been called.FirebaseMessaging
) do not bother with this.In order to simplify the service implementations and make them consistent I'm proposing the following changes:
FirebaseAuth
doesn't have any state that requires explicit tear down. Therefore remove the existing repetitive logic for throwing errors afterdelete()
is called.FirebaseService.destroy()
method non-abstract so that child classes are not forced to provide a no-op implementation. Child classes that do allocate managed resources (e.g.FirebaseDatabase
) can still override it to tear down those resources.FirebaseApp.delete()
in the API reference docs.This results in the following concrete behaviors after
FirebaseApp.delete()
:FirebaseXXXXX.getInstance()
methods will throw.FirebaseDatabase
andFirestoreClient
) will get cleaned up and become unusable.FirebaseApp
).Potential future work: If necessary we can implement a mechanism to block all rpc calls after
FirebaseApp.delete()
has been called. This is easy enough to enforce via the existingFirebaseRequestInitializer
. But methods that do not make rpc calls (e.g.FirebaseAuth.createCustomToken()
) will continue to work.