google_cloud_firestore: failed first read in runTransaction is also reported as an uncaught async error

Aperta Adatta ai principianti
#367 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 6 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
85/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
dart
Ambito
backend, databases

Direzione di ricerca

Leggi lib/src/transaction.dart, in particolare la prima lettura transazionale che assegna _transactionIdFuture. Controlla come viene gestito il future quando la lettura non riesce e confronta questo comportamento con il future restituito al chiamante. Conferma la correzione con la riproduzione descritta di runZonedGuarded: il chiamante dovrebbe ricevere l’errore senza che venga segnalato di nuovo come non intercettato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Package: google_cloud_firestore 0.5.5

What happens: When the first read inside runTransaction fails (for example a network error), the caller of runTransaction correctly receives the error, but the same error is also reported to the zone as an uncaught async error. In a server process with a default zone this shows up as a duplicate unhandled exception (and can terminate an isolate that treats uncaught errors as fatal).

Cause: In lib/src/transaction.dart, the first transactional read assigns

_transactionIdFuture = resultFuture.then((r) { ... });

and returns a separate resultFuture.then((r) => r.result) to the caller. When resultFuture fails, the caller's future is listened to, but _transactionIdFuture has no listener yet, so Dart reports its error as uncaught immediately. Rollback only awaits _transactionIdFuture later, after the error has already been reported.

Minimal reproduction:

  1. Use a Firestore instance whose HTTP client fails the first BatchGetDocuments / read request of a transaction (e.g. throws a SocketException).
  2. Run:
await runZonedGuarded(
  () async {
    try {
      await firestore.runTransaction((tx) => tx.get(firestore.doc('c/d')));
    } catch (e) {
      print('caller got: $e');
    }
  },
  (e, s) => print('uncaught: $e'),
);

Expected: only caller got: ....
Actual: caller got: ... and uncaught: ... with the same error instance.

Suggested fix: mark the stored future as handled right after it's created, so the error stays available to later awaits but isn't reported as uncaught:

_transactionIdFuture = resultFuture.then((r) { ... });
_transactionIdFuture!.ignore();

Future.ignore() only suppresses the uncaught report; awaiting _transactionIdFuture later (in rollback or queued reads) still throws the original error. We verified this locally against 0.5.5: with the line added, the uncaught report disappears and the caller and rollback behaviour are unchanged.

Workarounds in calling code (custom error zones) are fragile: they can hang a transaction when an error from a shared, lazily initialised client completes in a different error zone, so a fix in the package would be much safer.

Lingua principale
Dart
Stelle
180
Fork
73
Merge medio
5g 8h
PR unite (30g)
9

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di firebase/firebase-admin-dart

Tutte le issue di firebase/firebase-admin-dart

Issue simili

Altre issue su Dart

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.