Repository navigation
Conversation
Hold immediate scope parents weakly while retaining the SDK initialization root. This prevents escaping asynchronous tasks from retaining an unbounded chain of historical Scopes instances. Fixes #6248 Co-Authored-By: Claude <noreply@anthropic.com>
This was referenced Nov 17, 2026
📲 Install BuildsAndroid
|
…cope-parent-retention-v9-weak-parents # Conflicts: # sentry/src/main/java/io/sentry/Scopes.java
…cope-parent-retention-v9-weak-parents
This branch has not been deployed
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.
PR Stack (Scope Parent Retention)
📜 Description
Hold each forked
Scopesinstance's immediate parent through aWeakReference. If that parent has been collected,getParentScopes()returnsnulland ancestry traversal ends. Forks retain only the opaque SDK initialization token introduced in #6636, not a rootScopesinstance.This applies the behavior to all regular scope forks, so asynchronous wrappers and scheduler integrations do not need special task-specific fork APIs. It also makes ancestry and diagnostic chain traversal iterative.
💡 Motivation and Context
Escaping or self-rescheduling tasks can retain their captured scopes indefinitely. Strong parent links then keep every historical ancestor alive, producing an unbounded retention chain. Weak immediate parents allow those scopes—including the initialization root—to be collected, while the shared token preserves SDK initialization identity independently of ancestry.
Resolves #6248
💚 How did you test it?
make format apiScopesTestSentryTestSentryWrapperTestSentryContextWrapperTestThe regressions verify that immediate parents and the initialization root are collectable, collected ancestry terminates at
null, descendants remain usable, and SDK initialization identity continues to work through the shared token.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
Merge this PR into #6636 with a merge commit, then merge #6636 into the collection PR the same way.