Skip to content

Fix TOCTOU race in newEngineReference null checks during engine reset (#21404)#21572

Open
sean- wants to merge 2 commits intoopensearch-project:mainfrom
sean-:worktree-fix-engine-ref-race
Open

Fix TOCTOU race in newEngineReference null checks during engine reset (#21404)#21572
sean- wants to merge 2 commits intoopensearch-project:mainfrom
sean-:worktree-fix-engine-ref-race

Conversation

@sean-
Copy link
Copy Markdown
Contributor

@sean- sean- commented May 8, 2026

Store newEngineReference.get() in a local variable before the null check to prevent a race where another thread nulls the reference between the check and subsequent use, which would cause a NullPointerException.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

PR Reviewer Guide 🔍

(Review updated until commit 789103a)

Here are some key observations to aid the review process:

🧪 No relevant tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ No major issues detected

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

❌ Gradle check result for 974ecae: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

…opensearch-project#21404)

Store newEngineReference.get() in a local variable before the null check
to prevent a race where another thread nulls the reference between the
check and subsequent use, which would cause a NullPointerException.

Signed-off-by: Sean Chittenden <sean.chittenden@crowdstrike.com>
@sean- sean- force-pushed the worktree-fix-engine-ref-race branch from 974ecae to 24b6d00 Compare May 8, 2026 21:56
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

Persistent review updated to latest commit 24b6d00

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

❌ Gradle check result for 24b6d00: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@Override
public GatedCloseable<IndexCommit> acquireLastIndexCommit(boolean flushFirst) {
if (newEngineReference.get() == null) {
Indexer indexer = newEngineReference.get();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm fine with this change because it indeed does look like a TOCTOU race, but with the semantics of SetOnce it's actually impossible for the reference to change if newEngineReference.get() is not null.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

❌ Gradle check result for 24b6d00: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

Persistent review updated to latest commit 789103a

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

✅ Gradle check result for 789103a: SUCCESS

@codecov
Copy link
Copy Markdown

codecov Bot commented May 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.38%. Comparing base (8f72a95) to head (789103a).

Additional details and impacted files
@@             Coverage Diff              @@
##               main   #21572      +/-   ##
============================================
- Coverage     73.48%   73.38%   -0.11%     
+ Complexity    74646    74541     -105     
============================================
  Files          5980     5980              
  Lines        338777   338780       +3     
  Branches      48848    48848              
============================================
- Hits         248964   248610     -354     
- Misses        70026    70345     +319     
- Partials      19787    19825      +38     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants