fix: remove redundant cookie writes causing race conditions#1560
Draft
daniel-graham-amplitude wants to merge 14 commits intomainfrom
Draft
fix: remove redundant cookie writes causing race conditions#1560daniel-graham-amplitude wants to merge 14 commits intomainfrom
daniel-graham-amplitude wants to merge 14 commits intomainfrom
Conversation
… AMP-149016-is-enabled-diagnostics
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.
Summary
PROBLEM
This block of code has a race condition in it:
deviceIdwhich triggers updateStorage which won't includelastEventId,lastEventTime, etc... because it hasn't been written yetIf you refresh between #1 and #2 then it won't have
lastEventIdorlastEventTimein the cookies, which will cause them to be reset the next page and cause a new session_start event.SOLUTION
This fix adds a variable to disable update storage temporarily.
Checklist
Note
Medium Risk
Changes when
BrowserConfigpersists identity/session fields by batching initial writes into a singleupdateStorage()call, which could affect cookie/state consistency if any consumers relied on intermediate writes. Scope is limited to browser-side session storage updates and a small test/mock adjustment.Overview
Prevents redundant/partial cookie writes during
BrowserConfigconstruction by temporarily disablingupdateStorage()while setters run, then re-enabling and persisting once at the end (guarded via a new_disableStorageUpdateflag).Adds a note in the context plugin about atomizing event-id/time writes, and updates
getTopLevelDomaintests to stop stubbing a removed/unusedCookieStorage._isEnabledfield.Written by Cursor Bugbot for commit 8b2befe. This will update automatically on new commits. Configure here.