[cloud_firestore] iOS: transaction.get() after the native timeout aborts the app ("A transaction object cannot be used after its update callback has been invoked")
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 52/100
Línea de trabajo
Start with FLTTransactionStreamHandler.m around lines 62–115 and 141, then trace transaction storage and lookup in FLTFirebaseFirestorePlugin.m around lines 667–682 and 791–796. Check how the iOS transaction handler and tests cover timeout, retries, and operations arriving after an attempt ends. Done means late reads fail cleanly, timed-out attempts do not commit stale commands, and a regression test verifies the behavior.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Is there an existing issue for this?
- I have searched the existing issues.
Which plugins are affected?
Database
Which platforms are affected?
iOS
Description
A Dart transaction.get() can reach the native FIRTransaction after the transaction's update block has already returned. Firestore then fails an internal assertion and the process aborts (SIGABRT). It's an uncatchable native crash, not a Dart exception:
NSInternalInconsistencyException - FIRESTORE INTERNAL ASSERTION FAILED: A transaction object cannot be used after its update callback has been invoked. (expected !committed_)
Expected: a get that arrives after the native attempt has ended fails with a catchable FirebaseException (or the transaction fails cleanly), like the existing missing-transaction error.
Actual: the app is killed.
Where it happens (cloud_firestore 6.10.0, iOS sources)
FLTTransactionStreamHandler.m:62: the native update block posts the attempt to Dart, then waits on a semaphore for at mosttimeout(Dart default 30 s).FLTTransactionStreamHandler.m:65-115: on timeout it sends Dart adeadline-exceedederror event, then carries on. It appliesself.commandsand returnsnilwithout setting*pError, so the SDK goes on to commit.Transaction::Commitsetscommitted_ = truebefore the commit round trip.FLTFirebaseFirestorePlugin.m:791stores the attempt'sFIRTransactionin_transactions[transactionId]when the block starts.FLTFirebaseFirestorePlugin.m:796removes it only inended(), which runs from the completion block (FLTTransactionStreamHandler.m:141) after the commit finishes.FLTFirebaseFirestorePlugin.m:667-682(transactionGetApp) looks the transaction up by id and calls-[FIRTransaction getDocument:error:]with no check that the update block is still running.
So any Dart get that lands between the update block returning and the completion block (the commit round trip) calls Transaction::Lookup → EnsureCommitNotCalled() → assertion → abort. The Dart side has already been told the transaction failed (deadline-exceeded), but the user's handler is an ordinary async closure: it keeps running and issues its get.
How we hit it in production
A TestFlight build, iPhone, iOS 27.0.1. The app was suspended by iOS while a short read-modify-write transaction (one get, one set) was in flight. On resume (the user tapped a notification), the native wait's deadline had long passed, so the block timed out, returned and committed, just as the Dart handler resumed and sent its get. The crash was in the foreground, in the same second as the resume.
Any transaction can hit this whenever the Dart handler runs longer than timeout: app suspension, a slow first get on a poor connection, or a busy UI isolate.
Related
- The same bug in React Native Firebase: invertase/react-native-firebase#9298, fixed by PR #9303. Their bridge has the same structure (a semaphore wait with a timeout, and one transaction state per id). Their fix marks the attempt as returned after the wait, and rejects later operations from that attempt with a catchable error instead of letting them reach the SDK.
- Older FlutterFire reports of this assertion, all closed without a root cause: #1216, #1969, #6927.
Suggested fix
- Record per attempt that the update block has returned (for example a flag set, under the same lock as
_transactions, right after the semaphore wait). IntransactionGetApp, return aFlutterError(for exampleabortedordeadline-exceeded) instead of callinggetDocument:once it's set. - On timeout, fail the attempt (set
*pError, for exampleFIRFirestoreErrorCodeDeadlineExceededorAborted) instead of returningnil. Returningnillets the SDK commit a transaction that Dart has already been told failed. - Also:
resultTypeandcommandsare never reset between attempts. If a retried attempt times out, the block applies the previous attempt's commands (computed from the previous attempt's reads) to the new transaction.
Reproducing the issue
Timing-dependent: the get has to land inside the commit round trip after the native wait times out. This sketch hasn't been run as a standalone app; the production crash above is the evidence.
final db = FirebaseFirestore.instance;
final ref = db.doc('repro/doc');
for (var i = 0; i < 50; i++) {
try {
await db.runTransaction((tx) async {
await tx.get(ref); // a read, so the commit has a verify write
// Outlive the native wait (timeout below), then read again.
await Future<void>.delayed(Duration(milliseconds: 1000 + i * 5));
await tx.get(ref);
}, timeout: const Duration(seconds: 1));
} on FirebaseException catch (e) {
debugPrint('attempt $i: ${e.code}'); // deadline-exceeded is expected
}
}
Run it on a physical iOS device (a network link conditioner with added latency widens the window). Expected: each attempt fails with a catchable error. Actual: sooner or later the app aborts with the assertion above.
The production path: start a transaction, background the app so iOS suspends it before the handler's get, wait well past the timeout, then bring the app back.
Firebase Core version
4.15.0
Flutter Version
3.47.5
Relevant Log Output
Exception Type: EXC_CRASH (SIGABRT)
Termination Reason: SIGNAL 6 Abort trap: 6
NSInternalInconsistencyException - FIRESTORE INTERNAL ASSERTION FAILED: A transaction object cannot be used after its update callback has been invoked. (expected !committed_)
Crashed thread:
firebase::firestore::util::ObjcThrowHandler(...)
firebase::firestore::util::Throw(...)
firebase::firestore::util::internal::FailAssertion(...)
firebase::firestore::util::internal::FailAssertion(...)
firebase::firestore::core::Transaction::EnsureCommitNotCalled() + 104
firebase::firestore::core::Transaction::Lookup(...) + 56
-[FIRTransaction getDocument:completion:] + 264
-[FIRTransaction getDocument:error:] + 200
__78-[FLTFirebaseFirestorePlugin transactionGetApp:transactionId:path:completion:]_block_invoke + 172 (FLTFirebaseFirestorePlugin.m:682)
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_queue_override_invoke
_dispatch_root_queue_drain
_dispatch_worker_thread2
_pthread_wqthread
No other thread was inside a transaction update block at the time of the crash: the block had already returned.
Flutter dependencies
Expand Flutter dependencies snippet
Replace this line with the contents of your `flutter pub deps -- --style=compact`.
Additional context and comments
Our workaround: don't start a transaction unless the app is in the foreground (AppLifecycleState.resumed), and run anything held back on resume. That avoids the suspension path, but not a slow handler in the foreground.
The macOS implementation appears to share these Darwin sources, so it's probably affected too (not tested).
- Lenguaje dominante
- Dart
- Estrellas
- 9.3k
- Forks
- 4.1k
- Merge medio
- 2 d 2 h
- PR fusionados (30 d)
- 41
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de firebase/flutterfire
-
🚀 [firebase_core] Bump Firebase C++ SDK (13.13.0 → 14.0.0)Posiblemente ocupada @SelaseKay la tomó hoy. AbiertoNeeds Attention plugin: core type: enhancement
Dificultad 3/5 1-2 días Aptitud para principiantes 18/100
firebase/flutterfire#18798 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[firebase_auth]: authStateChanges() never emits null when the user is force-signed-out before the stream is listened to (iOS, macOS, Android)Posiblemente ocupada @JulianPscheid la tomó hace 1 día. AbiertoNeeds Attention platform: android platform: ios platform: macos plugin: auth type: bug
Dificultad 4/5 1-2 días Aptitud para principiantes 15/100
firebase/flutterfire#18796 ·
Los mantenedores suelen responder en 1 día
-
Needs Attention platform: ios plugin: messaging type: bug
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
firebase/flutterfire#18793 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[firebase_core] Firebase.initializeApp with demoProjectId crashes on iOS with SIGABRT (FIRInstallations validateAPIKey) - Follow-up to locked #17788Posiblemente ocupada @SelaseKay la tomó hace 1 día. AbiertoNeeds Attention platform: ios plugin: core reproduced type: bug type: crash
Dificultad 2/5 1-3 horas Aptitud para principiantes 22/100
firebase/flutterfire#18790 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[firebase_messaging]: Android: a burst of background messages starts a FlutterEngine per service start, and can lose all of themPosiblemente ocupada @SelaseKay la tomó hace 1 día. AbiertoNeeds Attention platform: android plugin: messaging reproduced type: bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 45/100
firebase/flutterfire#18789 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de firebase/flutterfire
Issues similares
-
backlog:low bug localization
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
simonoppowa/OpenNutriTracker#1366 ·
Los mantenedores suelen responder en 1 día
-
backlog documentation good first issue priority: medium
Dificultad 2/5 Medio día Aptitud para principiantes 78/100
-
coverage 1.16.0: format_coverage fails on the `{}` that `dart test --coverage` writes for fully skipped suitesPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
fyi-ecosystem platform-ios team-ios
Dificultad 1/5 Menos de una hora Aptitud para principiantes 70/100
flutter/flutter#194348 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día