Skip to content

fix(analytics-browser): cookie re-entrancy problem in isEnabled#1539

Merged
daniel-graham-amplitude merged 1 commit into
mainfrom
AMP-149016-cookie-enabled-reentrancy-bug
Feb 17, 2026
Merged

fix(analytics-browser): cookie re-entrancy problem in isEnabled#1539
daniel-graham-amplitude merged 1 commit into
mainfrom
AMP-149016-cookie-enabled-reentrancy-bug

Conversation

@daniel-graham-amplitude
Copy link
Copy Markdown
Collaborator

@daniel-graham-amplitude daniel-graham-amplitude commented Feb 16, 2026

Summary

Change "CookieStorage" isEnabled function to set "testValue" as a local variable instead of a static variable, which can cause re-entrancy issues.

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?: No

Note

Low Risk
Small, isolated change to cookie availability probing plus added tests; low risk aside from subtle behavior differences under concurrent calls.

Overview
Fixes a re-entrancy/race issue in CookieStorage.isEnabled() by removing the shared static testValue and using a per-call local value when writing/reading the temporary probe cookie.

Adds a Jest regression test that runs isEnabled() concurrently across instances, and includes a simple test-server HTML page to manually verify parallel and sequential isEnabled() calls stay consistently true.

Written by Cursor Bugbot for commit 4a661c4. This will update automatically on new commits. Configure here.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a re-entrancy bug in the CookieStorage.isEnabled() method where concurrent calls from multiple instances could interfere with each other due to a shared static variable. The fix changes testValue from a static class variable to a local variable within the method.

Changes:

  • Removed static testValue variable and made it local to isEnabled() method to prevent concurrent calls from different instances from interfering with each other
  • Added regression test to verify concurrent calls to isEnabled() work correctly
  • Added manual test HTML file to verify the fix in a browser environment

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/analytics-core/src/storage/cookie.ts Changed testValue from static class variable to local variable in isEnabled() method
packages/analytics-core/test/storage/cookies.test.ts Added regression test for re-entrancy issue with concurrent isEnabled() calls
test-server/cookies/is-enabled.html Added manual browser test for verifying parallel and sequential isEnabled() calls

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@Mercy811 Mercy811 left a comment

Choose a reason for hiding this comment

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

Thanks Dan!! LGTM!

@daniel-graham-amplitude daniel-graham-amplitude merged commit bb4b25e into main Feb 17, 2026
17 checks passed
@daniel-graham-amplitude daniel-graham-amplitude deleted the AMP-149016-cookie-enabled-reentrancy-bug branch February 17, 2026 17:28
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.

3 participants