Fix TOCTOU race causing NPE in Hibernate closeScope#11955
Conversation
There was a problem hiding this comment.
More details
The single-read fix correctly eliminates the NPE: capturing methodScope once into a local variable makes it immune to concurrent nullification by another thread. The reordering of setMethodScope(null) to before scope.close() is a strict improvement — it prevents a stale scope reference if close() throws and reduces a pre-existing window where same-thread re-entry during span finishing could leak a newly-created scope. Zero NPEs across 1,000 concurrent-nullification iterations.
📊 Validated against 6 scenarios · Open Bits AI session
🤖 Datadog Autotest · Commit fe6db89 · What is Autotest? · Any feedback? Reach out in #autotest
|
🎯 Code Coverage (details) 🔗 Commit SHA: fe6db89 | Docs | Datadog PR Page | Give us feedback! |
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
The merge request has been interrupted because the build 3377249345649551824 took longer than expected. The current limit for the base branch 'master' is 120 minutes. Possible reasons:
|
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
|
92779f6
into
master
What Does This Do
SessionMethodUtils.closeScope read SessionState.methodScope twice (once to check null, once to use) with no lock between the reads. A concurrent call could null it out in between, causing
Motivation
Additional Notes
Contributor Checklist
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issueJira ticket: [PROJ-IDENT]