fix: 25225 Fix race condition in EntityIdUniquenessValidator #25226
fix: 25225 Fix race condition in EntityIdUniquenessValidator #25226
Conversation
…false "entity not found" failures Signed-off-by: Ivan Malygin <ivan@swirldslabs.com>
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Coverage variation | ✅ +0.00% coverage variation (-1.00%) |
| Diff coverage | ✅ ∅ diff coverage |
Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (198285b) 100192 78875 78.72% Head commit (0b92f7f) 100192 (+0) 78875 (+0) 78.72% (+0.00%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>
Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#25226) 0 0 ∅ (not applicable) Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #25226 +/- ##
=========================================
Coverage 74.90% 74.90%
Complexity 11524 11524
=========================================
Files 2586 2586
Lines 100289 100289
Branches 11087 11087
=========================================
Hits 75119 75119
Misses 21364 21364
Partials 3806 3806 🚀 New features to boost your workflow:
|
Flaky Test(s) DetectedOne or more flaky tests were detected in this run. These tests have been reported before.
|
Problem
EntityIdUniquenessValidator#checkEntityUniquenessis invoked concurrently by multipleProcessorTaskthreads. Every 100,000 entities, one thread callsStateUtils.resetStateCache()(to prevent OOM), which clears thereadCacheof everyReadableKVStatewhile sibling threads are mid-get(). SinceReadableKVStateBase.get()writes to the cache and then re-reads it to produce its return value, a reset between those two steps causesget()to returnnullfor an entity that actually exists. The result:counterends up at0and the validator reports a spurious "No entity found for Entity ID X" failure.This manifested as intermittent failures on different entity IDs across runs.
Fix
Guard state access with a
ReentrantReadWriteLock:state.get(...)) acquire the read lock — concurrency preserved.resetStateCache()acquires the write lock — waits for in-flight reads to drain before clearing caches.Fixes #25225
Notes for reviewer:
Checklist