DuplicateTaskCompletionException in Firestore ThrottledForwardingExecutor causes fatal crash

Aperta
#8,021 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@wu-hui ci sta già lavorando.

Dal 8/4/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

api: firestore
Description

We're seeing a fatal DuplicateTaskCompletionException crash originating from Firestore's internal ThrottledForwardingExecutor. The crash is a race condition where a TaskCompletionSource is resolved twice — entirely within SDK code, with no app code in the stack trace.

Environment
  • Firebase BOM: 34.11.0
  • firebase-firestore: 26.1.2
  • play-services-tasks: 18.4.0
  • Android versions affected: Multiple (seen on API 30+)
  • Reproducibility: Intermittent — likely a threading race condition
Stack trace
Fatal Exception: com.google.android.gms.tasks.DuplicateTaskCompletionException: Complete with: result ip$a@22e602d
    at com.google.android.gms.tasks.zzw.zzg(com.google.android.gms:play-services-tasks@@18.4.0:1)
    at com.google.android.gms.tasks.zzw.zzc(com.google.android.gms:play-services-tasks@@18.4.0:2)
    at com.google.android.gms.tasks.zzx.run(com.google.android.gms:play-services-tasks@@18.4.0:3)
    at com.google.firebase.firestore.util.ThrottledForwardingExecutor.lambda$execute$0(ThrottledForwardingExecutor.java:54)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:923)
Analysis

The entire stack trace is inside SDK code — no app-level frames. ThrottledForwardingExecutor uses a semaphore to cap concurrency and falls back to running tasks synchronously on the calling thread when all slots are taken. This appears to create a window where two threads attempt to complete the same Task.

Suggested fix

Guard TaskCompletionSource.setResult() / setException() calls with trySetResult() / trySetException() in the code paths that run through ThrottledForwardingExecutor, or ensure the completion callback can only execute once.

Steps to reproduce

We have not been able to reproduce this on demand. It appears to be a timing-dependent race condition, possibly triggered by network transitions or app backgrounding during in-flight Firestore operations.

Lingua principale
Java
Stelle
2.6k
Fork
733
Merge medio
2g 15h
PR unite (30g)
72

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-android-sdk

Tutte le issue di firebase/firebase-android-sdk

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.