Fix VirtualThread support on multiple unmount/remount cycles by PerfectSlayer · Pull Request #10931 · DataDog/dd-trace-java
What Does This Do
This PR supersedes #10887 to fix context tracking on multiple virtual thread unmount / remount cycles.
Motivation
Previously, only one mount was supported, leading to context break.
Additional Notes
This PR is a re-implementation and adds the following changes compared to the original PR report:
- Updates the Javadoc to clarify the expected lifecycle and context related operations
- Distinguishes
afterTerminate/afterDonehooks - Uses typed
ContextScopeto reduce unnecessary type casts - Avoid unnecessary null checks for null-safe API calls
- Does not test remount cycle from the tests dedicated to VirtualThread and its builder API but creates a dedicated test suite
- Does not limit to test the missing behavior but tests other cases too like:
- multiple unmount/remount cycles
- implicit (tracing) context restored
- multiple virtual threads unmount/remount cycles
- sanity check without context
- Tries to trigger unmount more reliably - no dedicated API for so we can expect the test to flake
- Removes the logging correlation concern from the test cases to focus only on context tracking
- Adds thread join timeout
Contributor Checklist
- Format the title according to the contribution guidelines
- Assign the
type:and (comp:orinst:) labels in addition to any other useful labels - Avoid using
close,fix, or any linking keywords when referencing an issue
Usesolvesinstead, and assign the PR milestone to the issue - Update the CODEOWNERS file on source file addition, migration, or deletion
- Update public documentation with any new configuration flags or behaviors
Jira ticket: [PROJ-IDENT]
Note: Once your PR is ready to merge, add it to the merge queue by commenting /merge. /merge -c cancels the queue request. /merge -f --reason "reason" skips all merge queue checks; please use this judiciously, as some checks do not run at the PR-level. For more information, see this doc.