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

オープン 初心者向け
#367 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 6 日以内に返信

まだ誰も着手していません。

評価

難易度
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時間
マージ済み PR(30日)
9

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

firebase/firebase-admin-dart のほかの issue

firebase/firebase-admin-dart の issue をすべて見る

似ている issue

Dart の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。