Skip to content

fix: 25225 Fix race condition in EntityIdUniquenessValidator #25226

Open
imalygin wants to merge 1 commit intomainfrom
25225-entityIdUniqueness-fix
Open

fix: 25225 Fix race condition in EntityIdUniquenessValidator #25226
imalygin wants to merge 1 commit intomainfrom
25225-entityIdUniqueness-fix

Conversation

@imalygin
Copy link
Copy Markdown
Contributor

@imalygin imalygin commented May 2, 2026

Problem

EntityIdUniquenessValidator#checkEntityUniqueness is invoked concurrently by multiple ProcessorTask threads. Every 100,000 entities, one thread calls StateUtils.resetStateCache() (to prevent OOM), which clears the readCache of every ReadableKVState while sibling threads are mid-get(). Since ReadableKVStateBase.get() writes to the cache and then re-reads it to produce its return value, a reset between those two steps causes get() to return null for an entity that actually exists. The result: counter ends up at 0 and 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:

  • Reads (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

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

…false "entity not found" failures

Signed-off-by: Ivan Malygin <ivan@swirldslabs.com>
@imalygin imalygin added this to the v0.75 milestone May 2, 2026
@imalygin imalygin self-assigned this May 2, 2026
@imalygin imalygin requested a review from a team as a code owner May 2, 2026 02:38
@trunk-io
Copy link
Copy Markdown

trunk-io Bot commented May 2, 2026

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

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

@lfdt-bot
Copy link
Copy Markdown

lfdt-bot commented May 2, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented May 2, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Coverage ∅ diff coverage · +0.00% coverage variation

Metric Results
Coverage variation +0.00% coverage variation (-1.00%)
Diff coverage diff coverage

View coverage diff in Codacy

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
Copy link
Copy Markdown

codecov Bot commented May 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@            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           

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 2, 2026

Flaky Test(s) Detected

One or more flaky tests were detected in this run. These tests have been reported before.

Test Ticket
com.hedera.services.bdd.suites.freeze.JumpstartFileSuite#jumpstartsCorrectLiveWrappedRecordBlockHashes #24927
com.hedera.services.bdd.suites.validation.LogValidationTest#logsContainNoUnexpectedProblems #25154

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.

entityIdUniqueness validation fails intermittently in TestNet

2 participants