Skip to content

Fix RumWindowCallbacksRegistry for multiple SDK instances#3003

Merged
aleksandr-gringauz merged 2 commits into
developfrom
aleksandr-gringauz/rumwindowcallbackregistry-fix
Nov 14, 2025
Merged

Fix RumWindowCallbacksRegistry for multiple SDK instances#3003
aleksandr-gringauz merged 2 commits into
developfrom
aleksandr-gringauz/rumwindowcallbackregistry-fix

Conversation

@aleksandr-gringauz

@aleksandr-gringauz aleksandr-gringauz commented Nov 13, 2025

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixing RumWindowCallbacksRegistry for the case when there are multiple Datadog SDK instances in the app.

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)

  • 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)

@datadog-official

datadog-official Bot commented Nov 13, 2025

Copy link
Copy Markdown

🎯 Code Coverage
Patch Coverage: 100.00%
Total Coverage: 71.22% (-0.04%)

View detailed report

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: c3f7f8b | Docs | Datadog PR Page | Was this helpful? Give us feedback!

@codecov-commenter

codecov-commenter commented Nov 13, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.26%. Comparing base (bc35e34) to head (c3f7f8b).
⚠️ Report is 1101 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3003      +/-   ##
===========================================
+ Coverage    71.08%   71.26%   +0.18%     
===========================================
  Files          859      859              
  Lines        31315    31320       +5     
  Branches      5276     5276              
===========================================
+ Hits         22260    22320      +60     
+ Misses        7552     7515      -37     
+ Partials      1503     1485      -18     
Files with missing lines Coverage Δ
...nternal/utils/window/RumWindowCallbacksRegistry.kt 92.31% <100.00%> (ø)

... and 35 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aleksandr-gringauz
aleksandr-gringauz marked this pull request as ready for review November 13, 2025 12:47
@aleksandr-gringauz
aleksandr-gringauz requested review from a team as code owners November 13, 2025 12:47

private fun Window.tryToRemoveCallback() {
val currentCallback = callback
if (currentCallback is RumWindowCallback) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The problem is in this if (currentCallback is RumWindowCallback) check. Suppose we have 2 SDK instance and both installed their RumWindowCallbacks, wrapping the existing ones.

When removing the callback we need to check that we are removing "our" RumWindowCallback, but not the RumWindowCallback of the RumWindowCallbacksRegistry from a different SDK instance.

0xnm
0xnm previously approved these changes Nov 13, 2025
callback = currentCallback.wrapped
private fun Window.tryToRemoveCallback() {
val currentCallback = callback
if (currentCallback is RumWindowCallback && currentCallback.registry === this@RumWindowCallbacksRegistryImpl) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably alternative here is to check if RumWindowCallbacksRegistryImpl.callbacks.values() contains this callback, but we avoid doing this, because RumWindowCallbacksRegistryImpl.callbacks is a WeakHashMap?

I'm okay with solution if it don't impose leaks due to the circular dependency.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Probably alternative here is to check if RumWindowCallbacksRegistryImpl.callbacks.values() contains this callback, but we avoid doing this, because RumWindowCallbacksRegistryImpl.callbacks is a WeakHashMap?

This solution will also work, I just didn't think about it. It is actually a bit cleaner I think. Fixed.

I'm okay with solution if it don't impose leaks due to the circular dependency.

Kotlin GC can deal with circular references. Unless this "circle" goes through some C++ code. But this isn't our case I think. Or are you talking about something else?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It was just a raw assumption without going into the details.

Actually, we didn't check our SDK for leaks for a while, maybe we need to do a run of sample app with LeakCanary.

@aleksandr-gringauz

Copy link
Copy Markdown
Contributor Author

/merge

@dd-devflow-routing-codex

dd-devflow-routing-codex Bot commented Nov 13, 2025

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2025-11-13 16:21:49 UTC ℹ️ Start processing command /merge


2025-11-13 16:21:58 UTC ℹ️ MergeQueue: waiting for PR to be ready

This pull request is not mergeable according to GitHub. Common reasons include pending required checks, missing approvals, or merge conflicts — but it could also be blocked by other repository rules or settings.
It will be added to the queue as soon as checks pass and/or get approvals.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.


2025-11-13 20:22:04 UTC ⚠️ MergeQueue: This merge request was unqueued

devflow unqueued this merge request: It did not become mergeable within the expected time

@aleksandr-gringauz

Copy link
Copy Markdown
Contributor Author

/merge

@dd-devflow-routing-codex

dd-devflow-routing-codex Bot commented Nov 14, 2025

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2025-11-14 08:55:39 UTC ℹ️ Start processing command /merge


2025-11-14 08:55:45 UTC ℹ️ MergeQueue: waiting for PR to be ready

This pull request is not mergeable according to GitHub. Common reasons include pending required checks, missing approvals, or merge conflicts — but it could also be blocked by other repository rules or settings.
It will be added to the queue as soon as checks pass and/or get approvals.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.


2025-11-14 09:40:14 UTC ℹ️ MergeQueue: merge request added to the queue

The expected merge time in develop is approximately 1h (p90).


2025-11-14 09:53:59 UTC ℹ️ MergeQueue: Retrying because an high priority merge request needed to be processed first. No action is needed from your side.


2025-11-14 09:54:02 UTC ⚠️ MergeQueue: This merge request build was cancelled

[email protected] cancelled this merge request build

@aleksandr-gringauz

Copy link
Copy Markdown
Contributor Author

/merge -c

@dd-devflow-routing-codex

dd-devflow-routing-codex Bot commented Nov 14, 2025

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2025-11-14 09:53:53 UTC ℹ️ Start processing command /merge -c

@aleksandr-gringauz
aleksandr-gringauz merged commit 2a08737 into develop Nov 14, 2025
26 of 28 checks passed
@aleksandr-gringauz
aleksandr-gringauz deleted the aleksandr-gringauz/rumwindowcallbackregistry-fix branch November 14, 2025 09:54
@ncreated
ncreated restored the aleksandr-gringauz/rumwindowcallbackregistry-fix branch April 9, 2026 10:19
@0xnm
0xnm deleted the aleksandr-gringauz/rumwindowcallbackregistry-fix branch April 24, 2026 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants