-
Notifications
You must be signed in to change notification settings - Fork 492
Handle failure to persist GSON serialized JSON data (EXPOSUREAPP-3777) #1604
Handle failure to persist GSON serialized JSON data (EXPOSUREAPP-3777) #1604
Conversation
…es, we end up with an empty file. GSON deserializes this into a null object that looks like a non-null object until it is evaluated some time later. Force an evaluation via `require(it.size >= 0)` and delete the corrupt data file when catching the exception.
The This would point to the app process having died mid-write. |
Still think it's the cause, but I don't get how this could be so common. While our user numbers are high, hitting this exact execution point, is like getting hit by lightning 🤔 . |
Kudos, SonarCloud Quality Gate passed!
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Looks good to me, sadly i was not able to reproduce the error on any of my devices. I'm also quite confused about the frequency of this issue.
Upon further research the issue could also appear if GSON crashes while serializing the data, as the file writer we use will create an empty file. So in the timeline:
We end up with an empty data file too. I don't see how GSON could just crash randomly though. |
As the issue is most likely to occur during writing, we've added |
This PR requires 3 to 4 reviews as it can't be tested and wasn't catched by the testers during 1.6.0 testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
look conclusive in theory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, also @thomasaugsten tested it (s. jira comments)
Will follow up with another PR to rule out one more edge case. |
@ralfgehrer and me found the crash issue.
The file that should contain the json is empty.
When GSON reads it and deserializes it, it doesn't care that the file is empty, it will just create a new object that looks non-null, but is actually null. You only find out about that though when you try to access it.
In this case it was triggered by the mutate call here and the
mutate
extension function would calltoMutableMap()
where Kotlin would then notice that the object is actuallynull
.The symptoms for affected users are fixed by forcing an evaluation via
require(it.size >= 0)
and this triggers an exception, and we delete the corrupt data file.We are not 100% certain what leads to the empty file though, suspicions:
close()
callsflush()
implicitly, the underlying implementation does not?