-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
🐛 [cloud_firestore] database is locked (Sqlite code 5 SQLITE_BUSY) #6087
Comments
Hi @otopba, |
Hi! |
No, but my app uses streams and async code heavily, async queue keyword in stack trace makes me wonder if I missing some await keyword somewhere. |
I had raised #6592 regarding same issue. All crashes that i have checked occur when user is interacting with the notification(which i am sending via scheduled FCM notification). But i have also seen crashes where there was nothing in crashlytics logs |
I think this is caused when we try to initialise multiple firebase apps. I was initialising firebase app in main method of my flutter app and on onBackgroundMessage that i register with FIrebaseCloudMessage service. I removed it from onBackgroundMessage and i have not seen a single crash in last 2 days. I think i saw this msg in crash logs that it maybe due to multiple firebase app initialising. But since crashes are so many i could not find the message again to paste it here. The error message should be more clear here. |
Confirming that i have not seen this crash after i removed initialising firebase app second time in my code. |
@otopba, are you able to confirm if you are also initialising Firebase in the Or at least, that appears to be what happened with @ssabbarw. |
Yes, that seems to be the problem. The crash happens some time after the user receives the notification via onBackgroundMessage |
I Can also confirm this was happening with our app. |
Removing Firebase init from onBackgroundMessage doesn't compromise the functionality? For example, we are querying Firestore docs onBackgroundMessage... it will keep working without initializing Firebase? |
Hello! I get the same problem, here is a link to our sentry log: https://sentry.io/share/issue/3aad3b8795e042419857027891827607/ I am also using Firebase in the onBackgroundMessage. This happens when the app is not running in the background, and I get a notification. |
I think I got a fix!
And await |
Hey @najibghadri, thanks for the feedback! @otopba are you or anyone else experiencing the problem able to confirm this behaviour? |
@russellwheatley I will try in next release |
@russellwheatley Yes, that helped. The error no longer appears |
Hey @najibghadri @otopba, just to be clear, this is the setup you're referring to? Future<FirebaseApp> init() {
return Firebase.initializeApp(options: DefaultFirebaseConfig.platformOptions);
}
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await init();
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await init();
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
runApp(MessagingExampleApp());
} I'm looking to update documentation and example app with the latest setup. Thanks. |
No @russellwheatley this is still gonna call final firebaseInit =
Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
// and then await firebaseInit; wherever you want
...
await firebaseInit;
... It's a call to |
So your solution is this instead: final init = Firebase.initializeApp(options: DefaultFirebaseConfig.platformOptions);
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await init;
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await init;
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
runApp(MessagingExampleApp());
} |
You could say it's a drawback to have a global call to initializeApp, if you don't like this you can implement a proxy that checks if it has been called already, if not it does call initApp |
But the real solution would be if this is fixed on the Firebase level, it shouldn't fail on a repeated call. |
@russellwheatley Hi! In my project I did this: class FirebaseService {
FirebaseService._();
static final instance = FirebaseService._();
Completer? _completer;
Future<void> init() async {
Completer? completer = _completer;
if (completer == null) {
completer = Completer();
_completer = completer;
_initInternal();
}
return completer.future;
}
void _initInternal() async {
await Firebase.initializeApp(
options: const FirebaseOptions(
apiKey: "XXX",
authDomain: "XXX",
databaseURL: "XXX",
projectId: "XXX",
storageBucket: "XXX",
messagingSenderId: "XXX",
appId: "XXX",
measurementId: "XXX",
),
);
_completer!.complete();
}
} Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await FirebaseService.instance.init();
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await FirebaseService.instance.init();
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
runApp(App());
} |
Bug report
I have bug reports in my crashlytics:
Steps to reproduce
I don't know. But every crash was when the app was in the background
Flutter doctor
Click To Expand
Flutter dependencies
Run
flutter pub deps -- --style=compact
and paste the output below:Click To Expand
The text was updated successfully, but these errors were encountered: