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

Đang mở Phù hợp với người mới
#367 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 6 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
85/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
dart
Lĩnh vực
backend, databases

Hướng nghiên cứu

Đọc lib/src/transaction.dart, đặc biệt là lần đọc giao dịch đầu tiên gán _transactionIdFuture. Kiểm tra cách future được xử lý khi lần đọc thất bại và so sánh với future được trả về cho bên gọi. Xác nhận bản sửa bằng tình huống tái hiện runZonedGuarded đã mô tả: bên gọi phải nhận được lỗi mà lỗi đó không bị báo cáo thêm lần nữa là chưa được bắt.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Dart
Star
180
Fork
73
Merge trung bình
5 ngày 8 giờ
Pull request đã merge (30 ngày)
9

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của firebase/firebase-admin-dart

Tất cả issue của firebase/firebase-admin-dart

Issue tương tự

Thêm issue về Dart

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.