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

Abierto Apto para principiantes
#367 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 6 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
85/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
dart

Línea de trabajo

Lee lib/src/transaction.dart, especialmente la primera lectura transaccional que asigna _transactionIdFuture. Comprueba cómo se gestiona el future cuando falla la lectura y compáralo con el future que se devuelve al llamador. Confirma la corrección con la reproducción descrita de runZonedGuarded: el llamador debería recibir el error sin que se informe de nuevo como no capturado.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Dart
Estrellas
180
Forks
73
Merge medio
5 d 8 h
PR fusionados (30 d)
9

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de firebase/firebase-admin-dart

Todos los issues de firebase/firebase-admin-dart

Issues similares

Más issues de Dart

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.