Open eli1stark opened 3 months ago
Hello @eli1stark. Thank you for reporting this bug, Can you please try again with the latest firebase versions?
@TarekkMA Yes, it's still reproducible on the latest versions, forgot to mention that.
firebase_core: 3.1.0 cloud_firestore: 5.0.1
I've been able to reproduce this issue on the issue/12952 branch. I will inform the team, and we will look into fixing this.
Native Android Reproduction: Firebase Android Reproduction.
Is there an existing issue for this?
Which plugins are affected?
Firestore
Which platforms are affected?
Android, iOS
Description
The issue can be reproduced both on iOS and Android (simulator and physical device). I had to dig deep to be able to narrow it down to a simple function. The gist of the issue is that when the network is disabled and then enabled later,
FieldValue.increment()
may never reach Cloud Firestore, or maybe it reaches it, but there is some conflict there. When your balance is 0 and you callincrement(-10)
and thenincrement(10)
, you can end up with a balance of -10, which is wrong. You should end up with a balance of 0 always.This issue can be reproduced with a real network on a real device in real-life conditions, but it's hard and very cumbersome. This is why in my reproduction case, I used
firestore.disableNetwork()
andfirestore.enableNetwork()
.Also note that when you call the
simulate
function once, sometimes it can work as expected. I would say it causes the bug about 40-50% of the time. This is why I created thefastSimulate
function that increases the chance of missing events. When we callsimulate
orfastSimulate
, the expectation is that the value will always be 0 after all operations are synced with Firestore because we subtract and add the same amount.Reproducing the issue
firebase_core: 2.31.0
cloud_firestore: 4.17.3
FirebaseOptions.currentPlatform
ready.FirebaseOptions
to themain.dart
file.colId
,docId
, andvalueId
with your values.simulate
a couple of times with a delay of 2-3 seconds.simulate
doesn't work, try to pressfastSimulate
.-1
or lower.Firebase Core version
2.31.0
Flutter Version
3.22.2
Relevant Log Output
No response
Flutter dependencies
Expand
Flutter dependencies
snippet```yaml Replace this line with the contents of your `flutter pub deps -- --style=compact`. ```
Additional context and comments
Reproducible on the latest versions as of Jun 14th 2024.
firebase_core: 3.1.0 cloud_firestore: 5.0.1
https://github.com/firebase/flutterfire/assets/57593530/0d28e2a2-8185-4a25-bf2d-b6f14bd5d209