🐛 await re-grant if consent is revoked during session manager init#4605
Draft
thomas-lebeau wants to merge 1 commit into
Draft
🐛 await re-grant if consent is revoked during session manager init#4605thomas-lebeau wants to merge 1 commit into
thomas-lebeau wants to merge 1 commit into
Conversation
If tracking consent is revoked while startSessionManager is waiting on the cookie lock / Cookie Store call, the previous code resolved with undefined. RUM and Logs pre-start strategies invoke startSessionManager from trackingConsentState.onGrantedOnce, which fires exactly once and then unsubscribes — so a later re-grant in the same page could never bring the SDK back. The session manager was permanently stuck in pre-start state. Replace the early return with a wait loop: when consent isn't granted at the end of the async init, wait for the next grant (via onGrantedOnce) and re-resolve the initial state before installing the manager. Intervening state changes in other tabs are picked up by the re-resolve. Tests cover both the wait (promise stays pending while consent stays revoked) and the recovery (promise resolves to a working manager once consent is granted again).
🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: a559fc7 | Docs | Datadog PR Page | Give us feedback! |
Bundles Sizes Evolution
🚀 CPU Performance
🧠 Memory Performance
|
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.
Motivation
Addresses a P2 review comment on #4425.
When tracking consent is revoked while
startSessionManageris awaiting the cookie lock / Cookie Store call (the "async initialization" window), the previous code calledexpire()and resolved withundefined. The RUM and Logs pre-start strategies (preStartRum.ts:180,preStartLogs.ts:109) invokestartSessionManagerfromtrackingConsentState.onGrantedOnce, which fires exactly once and then unsubscribes (trackingConsent.ts:30-41). As a result, a customer who re-granted consent later in the same page could never bring the SDK back — the session manager was permanently stuck in pre-start state.Changes
packages/core/src/domain/session/sessionManager.ts: replace the early-return-on-revoked-consent branch with a wait loop. When consent isn't granted at the end of the async init, wait for the next grant viaonGrantedOnceand re-resolve the initial state before installing the manager (intervening state changes in other tabs are picked up by the re-resolve). If the manager is stopped while waiting, exit cleanly.packages/core/src/domain/session/sessionManager.spec.ts:flushMicrotaskshelper (10 cycles) so chained awaits —setSessionStateresolution, the.catch(monitorError)chain, and the post-await continuation — all run before assertions.Test instructions
yarn test:unit --spec packages/core/src/domain/session/sessionManager.spec.ts— the two new tests undertracking consentpass. RevertingsessionManager.tsmakes both fail (one because the promise resolves withundefinedtoo early, the other because the manager never installs after re-grant).yarn test:unit— full suite stays green (3534 tests).yarn typecheck/yarn lintclean.Checklist