Skip to content
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

RUM-2600: Add traversal flag to snapshot items #1837

Merged

Conversation

jonathanmos
Copy link
Contributor

What does this PR do?

Adds a flag to snapshot items that indicates that they have finished traversing the view tree. Also, increases the interval that snapshots are considered stale from 200ms to 1 second

Motivation

The RecordedDataQueueHandler in some situations could attempt to process an item that was still performing a traversal. Because items are inserted into the queue at the beginning of their traversals without nodes, the handler could regard the item as invalid and drop it from the queue. With this change, items that haven't finished traversals will only be dropped if stale.

Additional Notes

Anything else we should know when reviewing?

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@codecov-commenter
Copy link

codecov-commenter commented Jan 23, 2024

Codecov Report

Merging #1837 (b24509a) into develop (8145782) will increase coverage by 0.01%.
Report is 2 commits behind head on develop.
The diff coverage is 100.00%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1837      +/-   ##
===========================================
+ Coverage    83.49%   83.50%   +0.01%     
===========================================
  Files          467      467              
  Lines        16491    16491              
  Branches      2483     2485       +2     
===========================================
+ Hits         13769    13770       +1     
+ Misses        2043     2038       -5     
- Partials       679      683       +4     
Files Coverage Δ
...nreplay/internal/async/RecordedDataQueueHandler.kt 97.78% <ø> (ø)
...ay/internal/async/SnapshotRecordedDataQueueItem.kt 100.00% <100.00%> (ø)
...nternal/recorder/listener/WindowsOnDrawListener.kt 89.66% <100.00%> (+0.37%) ⬆️

... and 33 files with indirect coverage changes

@jonathanmos jonathanmos force-pushed the jmoskovich/RUM-2600/add-snapshot-traversal-flag branch 2 times, most recently from 9326bc1 to be5755d Compare January 23, 2024 20:55
@jonathanmos jonathanmos marked this pull request as ready for review January 23, 2024 21:33
@jonathanmos jonathanmos requested review from a team as code owners January 23, 2024 21:33
@@ -16,14 +16,20 @@ internal class SnapshotRecordedDataQueueItem(
internal val systemInformation: SystemInformation
) : RecordedDataQueueItem(recordedQueuedItemContext) {
internal var nodes = emptyList<Node>()
internal var isFinishedTraversal = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this one can be modified from the different threads, it should be either @Volatile or AtomicBoolean

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's modified only on the main thread - created as false and modified to true after the traversal. It may indeed be ww to make it volatile since the value could be read on another thread

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it is read in the isValid, isReady functions, which may be called from the worker thread:

  • isValid is called from triggerProcessingLoop, which is annotated with @WorkerThread and from shouldRemoveItem which is called from triggerProcessingLoop.
  • isReady is called also from multiple places of triggerProcessingLoop.

Looking on the threading model and call-chain I can see that RecordedDataQueueRefs#tryToConsumeItem may call that triggerProcessingLoop and RecordedDataQueueRefs#tryToConsumeItem may be called during the traversal.

So to be on the safe side and to protect from the changes of the the threading model in the future, it is still better to add it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same may be applied to the nodes property as well btw, maybe we should add @Volatile/AtomicReference there.

Anyway, passing mutable structures between the threads is already a dangerous idea.

@jonathanmos jonathanmos force-pushed the jmoskovich/RUM-2600/add-snapshot-traversal-flag branch from 993fb71 to 043209c Compare January 24, 2024 09:45
@jonathanmos jonathanmos force-pushed the jmoskovich/RUM-2600/add-snapshot-traversal-flag branch from 043209c to b24509a Compare January 25, 2024 09:00
@jonathanmos jonathanmos merged commit 62f730e into develop Jan 25, 2024
23 checks passed
@jonathanmos jonathanmos deleted the jmoskovich/RUM-2600/add-snapshot-traversal-flag branch January 25, 2024 09:23
@xgouchet xgouchet added this to the 2.6.0 milestone Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants