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

未关闭 适合新手
#367 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 6 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
85/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
dart
领域
backend, databases

调研方向

阅读 lib/src/transaction.dart,特别是首次赋值 _transactionIdFuture 的事务读取。检查读取失败时如何处理 future,并将其与返回给调用方的 future 进行比较。根据所描述的 runZonedGuarded 复现确认修复:调用方应收到错误,且该错误不会再次作为未捕获错误报告。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Dart
星标
180
派生
73
平均合并
5 天 8 小时
30 天内合并 PR
9

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

firebase/firebase-admin-dart 的其他 Issue

查看 firebase/firebase-admin-dart 的全部 Issue

相似的 Issue

更多 Dart Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。