Firestore: pending writes silently lost when issued around disableNetwork() / enableNetwork()
维护者通常 1 天内回复
@cherylEnkidu 已经在做这个了。
开始于 2026年7月22日。
评估
这个 Issue 还没有评估数据。
描述
[REQUIRED] Step 1: Describe your environment
- Android Studio version: any (reproduced on emulator and physical device)
- Firebase Component: Firestore
- Component version: reproduced with
firebase-bom:33.1.1(firebase-firestore); originally observed June 2024, still relevant as of the FlutterFire triage in July 2026
[REQUIRED] Step 2: Describe the problem
Steps to reproduce:
When a write (e.g. update() with FieldValue.increment()) is issued while the network is being toggled via disableNetwork() / enableNetwork(), the write can be silently dropped — it never reaches the backend and no error is surfaced. Starting from a field value of 0, calling increment(-1) followed by increment(+1) across a network toggle can leave the server value at -1 (or lower after repeated runs) instead of 0.
This was originally reported against FlutterFire in firebase/flutterfire#12952 with a Flutter reproduction (roughly 40–50% hit rate per attempt, near-certain when repeated). A FlutterFire maintainer then reproduced it in a pure native Android project using this SDK directly, with no Flutter involved: TarekkMA/firebase-android-reproduction @ ff-issue/12952. On that basis the FlutterFire issue was closed as an upstream native SDK bug (comment) — FlutterFire only forwards increment/disableNetwork/enableNetwork to this SDK. I'm filing this issue here to continue the investigation, as no upstream issue existed yet.
Trigger sequence (from the original report, translated to the Android SDK):
FirebaseFirestore db = FirebaseFirestore.getInstance();
DocumentReference doc = db.collection("test").document("doc"); // field "v" starts at 0
Map<String, Object> minusOne = new HashMap<>();
minusOne.put("v", FieldValue.increment(-1));
Map<String, Object> plusOne = new HashMap<>();
plusOne.put("v", FieldValue.increment(1));
doc.update(minusOne); // not awaited, as in real offline-capable apps
db.disableNetwork();
doc.update(plusOne);
db.enableNetwork();
Repeat the sequence a few times (a 2–3 second pause between runs is enough; firing many sequences concurrently makes it near-deterministic) and watch the document via a snapshot listener or the console.
The disableNetwork()/enableNetwork() calls are only a deterministic stand-in for an unstable real-world connection — the original report reproduced the same loss on a physical device with a genuinely flaky network, it is just far more cumbersome to trigger that way.
Expected result
Both queued writes are eventually delivered once the network is re-enabled — offline mutations are documented as queued and synced when connectivity returns. The field ends at 0 after every -1/+1 pair, every time.
Actual result
Intermittently (~40–50% of attempts in the Flutter harness, also confirmed in the native Android repro linked above) one of the writes is lost: the field ends at -1, and repeated runs drift further negative. The lost write's task never fails — there is no error signal that the mutation was dropped, so the client and server silently diverge.
Relevant Code:
- Native Android reproduction (by FlutterFire maintainer @TarekkMA): https://github.com/TarekkMA/firebase-android-reproduction/tree/ff-issue/12952
- Original Flutter reproduction with full source and screen recording: https://github.com/firebase/flutterfire/issues/12952
Note: the same behavior was also reproduced on iOS through FlutterFire, so the defect is likely shared across the native SDKs' offline mutation queue logic rather than being Android-specific.
- 主要语言
- Java
- 星标
- 2.6k
- 派生
- 733
- 平均合并
- 2 天 15 小时
- 30 天内合并 PR
- 72
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
firebase/firebase-android-sdk 的其他 Issue
-
api: remoteconfig
难度 2/5 1-3 小时 新手友好度 78/100
firebase/firebase-android-sdk#8827 ·
维护者通常 1 天内回复
-
Crashlytics plugin writes build ID lists in directory listing order, so APKs can differ between machines可能已有人在做 @mrober 于 8 天前认领。 未关闭api: crashlytics
难度 2/5 1-3 小时 新手友好度 72/100
firebase/firebase-android-sdk#8789 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
api: auth
难度 2/5 1-3 小时 新手友好度 68/100
firebase/firebase-android-sdk#8505 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 15/100
firebase/firebase-android-sdk#8835 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 25/100
firebase/firebase-android-sdk#8832 ·
维护者通常 1 天内回复
查看 firebase/firebase-android-sdk 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
NationalSecurityAgency/ghidra#10220 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 80/100
维护者通常 1 天内回复
-
RIS export splits an organization name containing “and” into multiple authors可能已有人在做 @Gautam-aman 今天认领。 未关闭status: needs-triage
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
FailureContext.java rounds down thresholds in lastedAtLeast()可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复