← Back to Pull requests

Fixes #1824: concurrent `BufferRecycler` pool-link lifecycle races #1825

Closed
unknown closed this pull request without merging on Nov 23, 2026 03:14 UTC
View on GitHub
unknown unknown commented on Nov 09, 2026 11:34 UTC
Author

Fixes: #1824

Summary

Make BufferRecycler pool-link operations atomic using the existing array-element VarHandle.

Previously, concurrent releaseToPool() calls could read the same pool reference before either cleared it, allowing the same recycler to be returned more than once.

Concurrent withPool() calls could also both observe an unlinked recycler and overwrite each other's pool association.

Changes

  • Use SLOTS.getAndSet() in releaseToPool() to atomically retrieve and clear the pool reference, preventing duplicate releases of the same link.

  • Use SLOTS.compareAndSet() in withPool() so only one concurrent caller can establish a pool link.

  • Use SLOTS.getVolatile() in isLinkedWithPool() for consistent visibility of the pool-link state.

  • Add regression tests for concurrent pool release and concurrent pool linking.
  • The changes reuse the existing VarHandle without introducing additional objects or changing the recycler's memory layout.

    Testing

    Before the fix, both new regression tests failed under concurrent execution:

    concurrentPoolReleaseReturnsRecyclerOnce:
      expected: <0> but was: <3>
    
    concurrentPoolLinkHasOneOwner:
      expected: <0> but was: <8>
    

    After the fix, all related tests passed:

    43 tests, 0 failures, 0 errors

    .\mvnw.cmd -B -ntp -Dsurefire.useModulePath=false -Dtest=BufferRecyclerTest,BufferRecyclerPoolTest,JsonBufferRecyclersTest test
    

    The module-path override was used to work around a local JUnit module-resolution issue; no build configuration changes were made.

    Scope

    The regression tests exercise concurrent calls to the low-level BufferRecycler lifecycle methods. They do not establish that concurrent parser/generator close() calls are supported.

    This change prevents multiple callers from releasing the same pool link, but it does not protect a newly acquired lease from a stale caller attempting to release it.

    The concurrent tests are scheduling-dependent stress tests.

    Related to #1802 and #1653.

    Diff: 259 lines (+194 / -65) across 3 files Reviewer: franz1981 Review duration: 19659m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 259 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.333
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1825"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.2% (MEDIUM) · Higher = larger blast radius
    39.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.5% · Safe to merge
    15.5%