-
Notifications
You must be signed in to change notification settings - Fork 441
Intermittent crashes when saving data to Firestore #1303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This issue does not seem to follow the issue template. Make sure you provide all the required information. |
Updated. |
Hi @khambadkone, Thanks for reporting this issue. I can bring this up to the team so that we can identify the causes of these crashes. For now, could you share the details (such as model and OS version) of the devices encountering the crashes? Additionally, could you confirm if version 9.6.0 reduces that crashes you're facing? |
This looks like a known issue that just came to our attention last week. If it's the issue I think it is, then it is specific to Android. Googlers can see b/251869890 for more details. Basically, Firestore's C++ JNI layer creates too many global references and eventually exhausts the 51200 global ref limit, which causes the app to crash. It is a long-standing bug but only now is starting to get noticed. I'm working on a fix, but the fix is non-trivial and ETA is probably mid-to-late November. Could you try running this code and see if it looks like the same crash you're getting in Crashlytics:
You should see an error like this in the logcat:
which is the telltale sign that you've experienced this issue. This crash is triggered by having documents with a large number of values (e.g. arrays of thousands of elements) or a large number of documents each with a large number of values (e.g. 60 documents each with an array of 100 elements). Given this information, does it sound like your use case could trigger this crash? |
Thank you for the reply. Appreciate it. Each Document is flat, but can have a large number of values. They are all key-value pairs only, however, which is a dump of some legacy JSON.
Will try mimicking a large dummy document to confirm it breaks at 60000 dummy values. |
Yes. Each key/value pair in a document uses 1 global ref. For map and array values, there is 1 global ref per entry. So calling DocumentReference.Set() with 51200 key/value pairs or with a single key/value pair whose value is a List of 51200 elements would trigger this crash. To be clear, this is NOT a good thing; the number of global refs should not be growing linearly with the size of the documents. That is the bug I am going to fix. |
Hi @dconeybe We did some tests ourselves, and find that the crash does not seem to depend only on the number of elements in the Document, but also on the periodicity of saves. We have the following snippet we use to keep adding more keys to our Document, and find that it triggers a crash even at 12000 unique keys, provided we add 1000 keys at a time. AddKeys is a method that accepts a number of keys to add. This differs from the behaviour you mentioned, so curious if this was a known issue fixed in a more recent version of Firestore, or if this is a new bug ?
|
@khambadkone Thank you for this extra info. Although 12,000 is significantly less than 51,200, maybe there ends up being some copies in memory that multiply the 12,000 to 24,000, and then you have two of them and, bam, you're at 48,000, very close to the 51,200 limit. So this could still be the global refs exhausted issue. If you're able to reproduce the crash, could you capture and post a logcat? If you're concerned about posting the logcat publicly, you could email to to me at my GitHub username at google.com. Would you be able to write a minimal app that reproduces the crash? If so, could you publish it to GitHub so I can reproduce the crash for myself? There are no other known related issues that have been fixed recently. This still sounds like the global refs exhausted issue, but it's impossible to tell without a logcat. Finally, you've reported this bug against SDK version 8.8.0, which is 9 months old. Back then we even used a different build system using Google internal build tools (now we use GitHub Actions runners to build). Could you try upgrading to the latest version (9.6.0 at the time of writing)? If we release a fix, you will need to upgrade anyways. Hope this helps! |
1. We get the same crash on 9.6. So it's the global refs issue.
2. My colleague will send a crashlog to you on your email address.
3. The sample project would be one in Unity. Is that fine with you?
Regarding the problem per-se, can you suggest a workaround ? We keep
setting the Document
regularly, depending on the player's progress. So, if there is a large
document, this will happen for players who engage.
The obvious solution is to prune the Document, but would like to know if
you can suggest alternatives?
…On Thu, Oct 13, 2022 at 8:20 PM Denver Coneybeare ***@***.***> wrote:
@khambadkone <https://github.com/khambadkone> Thank you for this extra
info. Although 12,000 is significantly less than 51,200, maybe there ends
up being some copies in memory that multiply the 12,000 to 24,000, and then
you have two of them and, bam, you're at 48,000, very close to the 51,200
limit. So this could still be the global refs exhausted issue.
If you're able to reproduce the crash, could you capture and post a
logcat? If you're concerned about posting the logcat publicly, you could
email to to me at my GitHub username at google.com.
Would you be able to write a minimal app that reproduces the crash? If so,
could you publish it to GitHub so I can reproduce the crash for myself?
There are no other known related issues that have been fixed recently.
This still sounds like the global refs exhausted issue, but it's impossible
to tell without a logcat.
Finally, you've reported this bug against SDK version 8.8.0, which is 9
months old. Back then we even used a different build system using Google
internal build tools (now we use GitHub Actions runners to build). Could
you try upgrading to the latest version (9.6.0 at the time of writing)? If
we release a fix, you will need to upgrade anyways.
Hope this helps!
—
Reply to this email directly, view it on GitHub
<#1303 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAP4WUT4T4AB5JU2ZSW6B33WDAOT5ANCNFSM6AAAAAARAZFRIU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Thank you for the logcat. That proves 100% that this is the global refs issue. There is no need to provide us any additional information. I've pasted two relevant excerpts from the logcat below:
Here is the (cleaned up) stack trace:
We are working on a fix for this. The only workaround is to reduce the number of values in your documents, either by removing key/value pairs or removing elements from arrays and maps in the document(s). Each key/value pair consumes a global ref, each element of an array consumes a global ref, and each key/value pair in a nested map consumes a global ref. |
@dconeybe Thank you for the help debugging this.
|
Calling The global references are in memory only for a short time (i.e. during the duration of the call to When the crash happens the document will not get created/updated in Firestore. The crash happens before it sends the RPC to the server to create/update the document. |
Update: The next Unity SDK release (scheduled for mid-November 2022) will pick up firebase/firebase-cpp-sdk#1111, which should buy you some breathing room. It's not a full fix, but avoids doubling the number of global refs used by |
@khambadkone I created a custom build of the Unity SDK that contains firebase/firebase-cpp-sdk#1111. Could you try it out and see if it fixes your issue? Just download |
Hey @khambadkone. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically. If you have more information that will help us get to the bottom of this, just add a comment! |
Since there haven't been any recent updates here, I am going to close this issue. @khambadkone if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this. |
FYI the Firebase Unity SDK v10.1.0 was released on November 7, 2022 and includes firebase/firebase-cpp-sdk#1111, which reduces the number of global references consumed by Firestore by about 50%. This will hopefully address many cases of the "global reference table overflow" crash. A full and proper fix is in development, but it is complex and is taking time to implement. |
[REQUIRED] Please fill in the following fields:
[REQUIRED] Please describe the question here:
Using a combination of Firebase Authenticate and Firestore, we save player information as Documents to a collection on Firestore. This data is a set of key-value data pairs, indicating player progress and the resulting document hierarchy is flat.
The game uses Firebase 8.8.0 with Unity 2020.3.32f1. The Unity code that saves this data is :-
saveData is a class
The code works for 90% of users, but we see the following two crashes in Crashyltics to the remaining 8-10% users :-
Crashlog 1:
Crashlog 2 :
On checking our logs and Firestore, we see data available for these users.
Am looking to understand what causes these errors in Crashlytics and the behaviour of Firestore when they occur ?
Crashlog 1 : Is this due to an issue converting a non-compliant data type in Firestore ? FieldValue documentation mentions unsupported types can cause a crash. If so, how can we identify the problem elements in Unity ? Why do we see data in FireStore despite these crashes ?
Crashlog 2 : What can cause a crash on SetAsync ? Is this due to the 1 second limit on saving documents ?
The text was updated successfully, but these errors were encountered: