firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.71k stars 3.98k forks source link

🐛 [cloud_firestore] Crash device when getting snapshot of document #3388

Closed mike-gallego closed 4 years ago

mike-gallego commented 4 years ago

Bug report

Describe the bug This just started happening randomly. Everything was working fine until one time I ran my app only to find it crashing.

Steps to reproduce

Steps to reproduce the behavior:

  1. Initialize Firebase app await Firebase.initializeApp();
  2. Create a CollectionReference CollectionReference zoneCollection = FirebaseFirestore.instance.collection('zones');
  3. Get data snapshot
    await zoneCollection.get().then((value) {
      value.docs.forEach((element) {
        GeoPoint zoneCenter = element.data()['location'];
        _circles.add(Circle(
          circleId: CircleId(element.data()['id']),
          center: LatLng(zoneCenter.latitude, zoneCenter.longitude),
          fillColor: Colors.redAccent.withOpacity(0.5),
          strokeWidth: 3,
          strokeColor: Colors.redAccent,
        ));
      });
    }) ;

Expected behavior

Get the data snapshot as it did before and add items to set without any crashes


Additional context

Add any other context about the problem here.


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 1.20.2, on Microsoft Windows [Version 10.0.18363.1016], locale en-US) [√] Android toolchain - develop for Android devices (Android SDK version 29.0.2) [√] Android Studio (version 3.5) [√] VS Code (version 1.48.2) [√] Connected device (1 available) • No issues found! ``` Console output: ``` W/DynamiteModule(20104): Local module descriptor class for providerinstaller not found. W/ConnectivityManager.CallbackHandler(20104): callback not found for CALLBACK_AVAILABLE message I/DynamiteModule(20104): Considering local module providerinstaller:0 and remote module providerinstaller:0 W/ProviderInstaller(20104): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0. W/ConnectivityManager.CallbackHandler(20104): callback not found for CALLBACK_AVAILABLE message W/DynamiteModule(20104): Local module descriptor class for providerinstaller not found. I/DynamiteModule(20104): Considering local module providerinstaller:0 and remote module providerinstaller:0 W/ProviderInstaller(20104): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0. W/DynamiteModule(20104): Local module descriptor class for providerinstaller not found. I/DynamiteModule(20104): Considering local module providerinstaller:0 and remote module providerinstaller:0 W/ProviderInstaller(20104): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0. D/AndroidRuntime(20104): Shutting down VM E/AndroidRuntime(20104): FATAL EXCEPTION: main E/AndroidRuntime(20104): Process: com.maginate.whats_poppin, PID: 20104 E/AndroidRuntime(20104): java.lang.RuntimeException: Internal error in Cloud Firestore (21.4.3). E/AndroidRuntime(20104): at com.google.firebase.firestore.util.AsyncQueue.lambda$panic$3(com.google.firebase:firebase-firestore@@21.4.3:534) E/AndroidRuntime(20104): at com.google.firebase.firestore.util.AsyncQueue$$Lambda$3.run(Unknown Source:2) E/AndroidRuntime(20104): at android.os.Handler.handleCallback(Handler.java:883) E/AndroidRuntime(20104): at android.os.Handler.dispatchMessage(Handler.java:100) E/AndroidRuntime(20104): at android.os.Looper.loop(Looper.java:214) E/AndroidRuntime(20104): at android.app.ActivityThread.main(ActivityThread.java:7682) E/AndroidRuntime(20104): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(20104): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516) E/AndroidRuntime(20104): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950) E/AndroidRuntime(20104): Caused by: java.lang.RuntimeException: android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5 SQLITE_BUSY) E/AndroidRuntime(20104): at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor.lambda$executeAndReportResult$1(com.google.firebase:firebase-firestore@@21.4.3:325) E/AndroidRuntime(20104): at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor$$Lambda$2.run(Unknown Source:4) E/AndroidRuntime(20104): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462) E/AndroidRuntime(20104): at java.util.concurrent.FutureTask.run(FutureTask.java:266) E/AndroidRuntime(20104): at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301) E/AndroidRuntime(20104): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) E/AndroidRuntime(20104): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) E/AndroidRuntime(20104): at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor$DelayedStartFactory.run(com.google.firebase:firebase-firestore@@21.4.3:229) E/AndroidRuntime(20104): at java.lang.Thread.run(Thread.java:919) E/AndroidRuntime(20104): Caused by: android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5 SQLITE_BUSY) E/AndroidRuntime(20104): at android.database.sqlite.SQLiteConnection.nativeExecute(Native Method) E/AndroidRuntime(20104): at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:648) E/AndroidRuntime(20104): at android.database.sqlite.SQLiteSession.beginTransactionUnchecked(SQLiteSession.java:325) E/AndroidRuntime(20104): at android.database.sqlite.SQLiteSession.beginTransaction(SQLiteSession.java:300) E/AndroidRuntime(20104): at android.database.sqlite.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:583) E/AndroidRuntime(20104): at android.database.sqlite.SQLiteDatabase.beginTransactionWithListener(SQLiteDatabase.java:546) E/AndroidRuntime(20104): at com.google.firebase.firestore.local.SQLitePersistence.runTransaction(com.google.firebase:firebase-firestore@@21.4.3:190) E/AndroidRuntime(20104): at com.google.firebase.firestore.local.LocalStore.startMutationQueue(com.google.firebase:firebase-firestore@@21.4.3:159) E/AndroidRuntime(20104): at com.google.firebase.firestore.local.LocalStore.start(com.google.firebase:firebase-firestore@@21.4.3:155) E/AndroidRuntime(20104): at com.google.firebase.firestore.core.FirestoreClient.initialize(com.google.firebase:firebase-firestore@@21.4.3:288) E/AndroidRuntime(20104): at com.google.firebase.firestore.core.FirestoreClient.lambda$new$0(com.google.firebase:firebase-firestore@@21.4.3:109) E/AndroidRuntime(20104): at com.google.firebase.firestore.core.FirestoreClient$$Lambda$1.run(Unknown Source:8) E/AndroidRuntime(20104): at com.google.firebase.firestore.util.AsyncQueue.lambda$enqueue$2(com.google.firebase:firebase-firestore@@21.4.3:436) E/AndroidRuntime(20104): at com.google.firebase.firestore.util.AsyncQueue$$Lambda$2.call(Unknown Source:2) E/AndroidRuntime(20104): at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor.lambda$executeAndReportResult$1(com.google.firebase:firebase-firestore@@21.4.3:322) E/AndroidRuntime(20104): ... 8 more E/SQLiteLog(20104): (5) database is locked E/SQLiteDatabase(20104): Failed to open database '/data/user/0/com.maginate.whats_poppin/databases/firestore.%5BDEFAULT%5D.what-s-poppin-43bda.%28default%29'. E/SQLiteDatabase(20104): android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5 SQLITE_BUSY): , while compiling: PRAGMA journal_mode E/SQLiteDatabase(20104): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) E/SQLiteDatabase(20104): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:986) E/SQLiteDatabase(20104): at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:729) E/SQLiteDatabase(20104): at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:376) E/SQLiteDatabase(20104): at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:316) E/SQLiteDatabase(20104): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:224) E/SQLiteDatabase(20104): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:197) E/SQLiteDatabase(20104): at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:505) E/SQLiteDatabase(20104): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:206) E/SQLiteDatabase(20104): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:198) E/SQLiteDatabase(20104): at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:930) E/SQLiteDatabase(20104): at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:910) E/SQLiteDatabase(20104): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:774) E/SQLiteDatabase(20104): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:763) E/SQLiteDatabase(20104): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:374) E/SQLiteDatabase(20104): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:317) E/SQLiteDatabase(20104): at com.google.firebase.firestore.local.SQLitePersistence.start(com.google.firebase:firebase-firestore@@21.4.3:132) E/SQLiteDatabase(20104): at com.google.firebase.firestore.core.FirestoreClient.initialize(com.google.firebase:firebase-firestore@@21.4.3:270) E/SQLiteDatabase(20104): at com.google.firebase.firestore.core.FirestoreClient.lambda$new$0(com.google.firebase:firebase-firestore@@21.4.3:109) E/SQLiteDatabase(20104): at com.google.firebase.firestore.core.FirestoreClient$$Lambda$1.run(Unknown Source:8) E/SQLiteDatabase(20104): at com.google.firebase.firestore.util.AsyncQueue.lambda$enqueue$2(com.google.firebase:firebase-firestore@@21.4.3:436) E/SQLiteDatabase(20104): at com.google.firebase.firestore.util.AsyncQueue$$Lambda$2.call(Unknown Source:2) E/SQLiteDatabase(20104): at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor.lambda$executeAndReportResult$1(com.google.firebase:firebase-firestore@@21.4.3:322) E/SQLiteDatabase(20104): at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor$$Lambda$2.run(Unknown Source:4) E/SQLiteDatabase(20104): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462) E/SQLiteDatabase(20104): at java.util.concurrent.FutureTask.run(FutureTask.java:266) E/SQLiteDatabase(20104): at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301) E/SQLiteDatabase(20104): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) E/SQLiteDatabase(20104): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) E/SQLiteDatabase(20104): at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor$DelayedStartFactory.run(com.google.firebase:firebase-firestore@@21.4.3:229) E/SQLiteDatabase(20104): at java.lang.Thread.run(Thread.java:919) I/Process (20104): Sending signal. PID: 20104 SIG: 9 Lost connection to device. Exited (sigterm) ``` --- ### Flutter dependencies Run `flutter pub deps -- --style=compact` and paste the output below:
Click To Expand ``` - animated_widgets 1.0.6 [flutter vector_math] - cloud_firestore 0.14.0+2 [flutter meta quiver firebase_core firebase_core_platform_interface cloud_firestore_platform_interface cloud_firestore_web] - cupertino_icons 0.1.3 - firebase_core 0.5.0 [firebase_core_platform_interface flutter quiver meta firebase_core_web] - flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine] - geolocator 5.3.2+2 [flutter meta equatable google_api_availability location_permissions vector_math] - google_maps_flutter 0.5.30 [flutter flutter_plugin_android_lifecycle google_maps_flutter_platform_interface] - intl 0.16.1 [path] - location 3.0.2 [flutter meta location_platform_interface location_web] - shimmer 1.1.1 [flutter] dev dependencies: - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data] transitive dependencies: - async 2.4.2 [collection] - boolean_selector 2.0.0 [source_span string_scanner] - characters 1.0.0 - charcode 1.1.3 - clock 1.0.1 [meta] - cloud_firestore_platform_interface 2.0.1 [flutter meta collection firebase_core plugin_platform_interface] - cloud_firestore_web 0.2.0+1 [flutter flutter_web_plugins firebase http_parser meta firebase_core cloud_firestore_platform_interface js] - collection 1.14.13 - equatable 1.2.4 [collection meta] - fake_async 1.1.0 [clock collection] - firebase 7.3.0 [http http_parser js] - firebase_core_platform_interface 2.0.0 [flutter meta plugin_platform_interface quiver] - firebase_core_web 0.2.0 [firebase firebase_core_platform_interface flutter flutter_web_plugins meta js] - flutter_plugin_android_lifecycle 1.0.8 [flutter] - flutter_web_plugins 0.0.0 [flutter characters collection meta typed_data vector_math] - google_api_availability 2.0.4 [flutter] - google_maps_flutter_platform_interface 1.0.4 [flutter meta plugin_platform_interface stream_transform] - http 0.12.2 [http_parser path pedantic] - http_parser 3.1.4 [charcode collection source_span string_scanner typed_data] - js 0.6.2 - location_permissions 3.0.0+1 [flutter meta] - location_platform_interface 1.0.0 [flutter meta plugin_platform_interface] - location_web 1.0.0 [flutter flutter_web_plugins location_platform_interface http_parser meta js] - matcher 0.12.8 [stack_trace] - meta 1.1.8 - path 1.7.0 - pedantic 1.9.0 - plugin_platform_interface 1.0.2 [meta] - quiver 2.1.3 [matcher meta] - sky_engine 0.0.99 - source_span 1.7.0 [charcode collection meta path term_glyph] - stack_trace 1.9.5 [path] - stream_channel 2.0.0 [async] - stream_transform 1.2.0 - string_scanner 1.0.5 [charcode meta source_span] - term_glyph 1.1.0 - test_api 0.2.17 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher] - typed_data 1.2.0 [col ```
marciorr commented 4 years ago

I was having a similar crash in my application, but I wasn't sure where the problem was, so I reverted my Firebase dependencies to the version prior to Firebase Core 0.5.0 and now everything is fine again. I think there is something causing these crashes in the new dependencies. I hope someone points out a solution soon.

TahaTesser commented 4 years ago

Hi @mikeyyg96 Not able to reproduce this issue with document snapshots

Please try this code sample

code sample ```dart import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); FirebaseApp app = await Firebase.initializeApp(); assert(app != null); runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Material App', theme: ThemeData.dark(), home: Home(), ); } } class Home extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Firestore Example'), ), body: Center( child: BookList(), ), ); } } class BookList extends StatelessWidget { @override Widget build(BuildContext context) { return StreamBuilder( stream: FirebaseFirestore.instance.collection('zones').snapshots(), builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.hasError) return new Text('Error: ${snapshot.error}'); switch (snapshot.connectionState) { case ConnectionState.waiting: return new Text('Loading...'); default: return new ListView( children: snapshot.data.docs.map((DocumentSnapshot document) { return new ListTile( title: new Text(document.data()['id'] ?? ''), subtitle: new Text(document.data()['location'] ?? ''), ); }).toList(), ); } }, ); } } ```
  firebase_core: ^0.5.0
  cloud_firestore: ^0.14.0

Can you please provide flutter run --verbose logs, and a minimal complete reproducible code sample Thank you

SpiegelSoft commented 4 years ago

I am encountering a similar issue, on iOS only, in which snapshots randomly stop working, and then resume again.

google-oss-bot commented 4 years ago

Hey @mikeyyg96. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 4 years ago

Since there haven't been any recent updates here, I am going to close this issue.

@mikeyyg96 if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.