RUM-11821: Fix crash in KronosTimeProvider #3014
Open
+91
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
See the ticket for a stacktrace.
I haven't managed to determine how widespread this crash is, I can't find it in the list of crashes on google play console, I only can see it through the link shared by a single customer though google play console.
I haven't managed to reproduce it either.
The crash happens most likely because (it is the most plausible explanation I can come up with):
kronosClock.shutdownhere.kronosClock.getCurrentTimeMsis called as a result of this call tosdkCore.time.deviceTimeNs.ensureServiceIsRunningcall throwsIllegalStateExceptionhere.sdkCore.time.deviceTimeNscan get the oldtimeProvider, after thatkronosClock.shutdownis called on another thread and finallysdkCore.time.deviceTimeNsinteracts with this clock using the old 'timeProvider`.This PR does the following:
Add try/catch in
KronosTimeProviderso that it becomes physically impossible to crash if by some reason we interact with an already shutdown kronos clock.We could make
timeProvidervolatile. But it will not help with the point 4.sdkCore.time.deviceTimeNsis not "atomic", clock can be shut down at any point during execution of this code, so the best we can do is try/catch.Motivation
What inspired you to submit this pull request?
Additional Notes
Anything else we should know when reviewing?
Review checklist (to be filled by reviewers)