Enable recording session if first RUM message happened before init#1777
Merged
louiszawadzki merged 3 commits intoJan 3, 2024
Merged
Conversation
louiszawadzki
commented
Dec 19, 2023
Contributor
Author
|
Other solutions I had: Moving
|
louiszawadzki
force-pushed
the
louiszawadzki/rum-2293/fix-sr-race-condition-with-rum-event
branch
from
December 19, 2023 17:03
3712085 to
14858da
Compare
louiszawadzki
force-pushed
the
louiszawadzki/rum-2293/fix-sr-race-condition-with-rum-event
branch
from
December 20, 2023 09:01
14858da to
7d3a21d
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## develop #1777 +/- ##
===========================================
+ Coverage 83.46% 83.47% +0.01%
===========================================
Files 469 469
Lines 16431 16434 +3
Branches 2465 2466 +1
===========================================
+ Hits 13714 13718 +4
+ Misses 2038 2034 -4
- Partials 679 682 +3
|
mariusc83
reviewed
Dec 20, 2023
mariusc83
approved these changes
Dec 22, 2023
jonathanmos
approved these changes
Dec 24, 2023
louiszawadzki
deleted the
louiszawadzki/rum-2293/fix-sr-race-condition-with-rum-event
branch
January 3, 2024 10:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?
This fixes a race condition that was quite present in RN - see description below.
The solution I choose was to move the responsibility of checking for initialization from
startRecordingintocheckStatusAndApplySample.The
startRecordingmethod is easier to work with if it just performs an atomic action (likestopRecording).It seems fit to put the check in
checkStatusAndApplySamplesince it's the method that registers thecurrentRumSessionIdthat was creating the lock before.Motivation
Description of the race condition
This can happen in any Android app, it’s just that conditions for creating the race condition are more present in RN since we collect JS framerate through RUM events on every frame.
The race condition happens in SessionReplayFeature.kt, in the onInitialize function:
This is called when we call SessionReplay.enable.
By setting the event receiver, we listen on all RUM events. Now if a RUM event happens before we call initialized.set(true), here is what is going to happen in SessionReplayFeature:
So far the Session Replay is not recording, and on the next RUM event, even if initialized.set(true) has been called:
So we fail to ever initialize the SDK.
Additional Notes
Anything else we should know when reviewing?
Review checklist (to be filled by reviewers)