Commit 09b55546 authored by Grisha Kruglov's avatar Grisha Kruglov
Browse files

Initialize accountManager on the main thread during migration

This fixes fallback from in which
FennecMigrator changed to accept a Lazy-wrapped reference to the account manager.

This was done so that during regular (non-migrating) startup, a simple act of building a no-op
migrator will not cause account manager initialization.

However, during a migrating startup this creates a race to initialize account manager.
Two participants in this race are:
1) FenixApplication running expensive operations (such as storage init, account manager init)
after visual completeness. However, currently that just entails a 5 second delay from `onStart`.
2) FxA migration, which runs roughly at the mid-point of the migration.

Account manager currently can't be initialized on a background thread (or it will crash).
FxA migration runs on a background thread, so if (2) wins (that is, migrations before FxA migration take
less than 5 seconds), then migration will crash.

This patch adds an eager initialization right before we kick-off migrations but are still on the main thread,
iff an FxA migration will be executed.
parent 2f1be9b4
......@@ -504,6 +504,13 @@ class FennecMigrator private constructor(
return result
// If we need to run an FxA migration later, first make sure 'accountManager' is initialized
// while we're still on the main thread. This is necessary because accountManager can't be
// initialized on a background thread.
if (migrationsToRun.any { it.migration is Migration.FxA }) {
return runMigrationsAsync(store, migrationsToRun)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment