Repository navigation
Add regression test for ReplicatedAccessStorage race that evicted a just-created entity (UNKNOWN_ROLE) - #106525
Merged
fm4v merged 11 commits intoJul 17, 2026
Merged
Conversation
…ntity `ZooKeeperReplicator::refreshEntities(all=false)`, run by the background watch thread, read the `/uuid` children list via `getChildrenWatch` without holding `mutex` and only then took the lock to call `memory_storage.removeAllExcept(snapshot)`. A concurrent `insertEntity` (which creates the znode first and only then takes `mutex` to put the entity into `memory_storage`) could commit an entity after the snapshot was taken but before the watch thread acquired the lock, so `removeAllExcept` evicted the freshly inserted entity. Any statement resolving it by name in that window failed with `There is no role ... (UNKNOWN_ROLE)`, even on the same session that had just created the role (e.g. `CREATE USER ... DEFAULT ROLE`, `CREATE QUOTA ... TO`). Acquire `mutex` before reading the children list so the snapshot is consistent with the in-memory state, matching the `all=true` branch which already reads entities from ZooKeeper under the lock. Reproducer and analysis: ClickHouse#106521 Originally observed as a flaky clickhouse-backup TestRBAC failure: https://github.com/Altinity/clickhouse-backup/actions/runs/26991435518/job/79652420544 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…race Stress test in `test_replicated_users`: concurrently create a role and immediately reference it by name (`CREATE USER ... DEFAULT ROLE`, `CREATE QUOTA ... TO`), with background churn keeping the `/uuid` children list volatile and many seeded entities widening the eviction window. On the buggy build the freshly created role is evicted from the local cache by the background watch refresh and one of the referencing statements fails with `There is no role ... (UNKNOWN_ROLE)`; with the fix it never does. The detection logic was validated locally against an unpatched clickhouse-server 26.3.4.11: it reproduces `UNKNOWN_ROLE` within ~17s. Related: ClickHouse#106521 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Explain in the test why the stress driver is an in-container bash script with background jobs and `wait`, rather than Python threads driving `node.query` from the host (a host<->container round trip per iteration would lower the iteration rate and weaken reproduction of this narrow race) or `xargs -P` (only replaces the `& ... wait` fan-out while forcing the worker bodies into a third level of nested quoting). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…plicated_rbac_race_condition
Contributor
|
Workflow [PR], commit [e96f0f0] Summary: ✅ AI ReviewSummaryAdds a probabilistic integration regression test for the Final Verdict
|
…plicated_rbac_race_condition
…esolution The fix for the UNKNOWN_ROLE race was already merged into master via ClickHouse#107097 (refresh_mutex + scoped mutex locks at publish points). The merge of master into this branch (db83926) incorrectly kept the older approach's outer std::lock_guard lock{mutex} before getChildrenWatch on top of it, producing a double lock of mutex in refreshEntities and failing the build with -Wshadow and -Wthread-safety-analysis: https://github.com/ClickHouse/ClickHouse/actions/runs/29334767283/job/87091850817 Remove the leftover hunk so ZooKeeperReplicator.cpp matches master; this PR now only adds the integration test. Co-Authored-By: Claude Fable 5 <[email protected]>
…in the test The victim chain does by-name lookups of three just-created entities (settings profile, role, user), and the ReplicatedAccessStorage race is generic across entity types, but the detection matched only UNKNOWN_ROLE. If the race hit the profile lookup first, the multiquery failed with THERE_IS_NO_PROFILE before ever reaching the role reference and the iteration was silently retried, so a buggy build could print NO_RACE. Match UNKNOWN_ROLE, THERE_IS_NO_PROFILE, UNKNOWN_USER and the generic "There is no" text from IAccessStorage::throwNotFound instead. ClickHouse#106525 (comment) Co-Authored-By: Claude Fable 5 <[email protected]>
The fix itself was merged via ClickHouse#107097, so this PR is test-only now and Bugfix validation no longer applies. Co-Authored-By: Claude Fable 5 <[email protected]>
Two review findings on the in-container driver: 1. `local w=$1 name="race_$w"` dies under `set -u` with "w: unbound variable": bash expands the whole `local` command line before performing any of its assignments. Every victim worker died before its first iteration, and since a bare `wait` discards worker exit statuses, the driver still printed `NO_RACE` - the test passed without issuing a single victim query. Split the declarations and wait on each collected worker PID, turning nonzero worker exits into a driver failure (`WORKER_FAILED`, exit 1). 2. The detection `case` silently retried every client failure other than the targeted not-found errors until timeout. Now a clean success continues the loop, the specific race detections stop it, and any other nonzero client result fails the worker and the driver, so the test cannot pass while never exercising the intended path. Also fail the driver if seeding the profiles fails (`SEED_FAILED`). Verified with a stub clickhouse-client: clean run -> NO_RACE (exit 0), race errors (UNKNOWN_ROLE / THERE_IS_NO_PROFILE) -> RACE_DETECTED (exit 0), unrelated error -> WORKER_FAILED (exit 1), failing seed -> SEED_FAILED (exit 1). ClickHouse#106525 (comment) ClickHouse#106525 (comment) Co-Authored-By: Claude Fable 5 <[email protected]>
The integration-test containers mount the server binary at /usr/bin/clickhouse and have no clickhouse-client symlink, so every client call in the driver failed with "clickhouse-client: command not found". Before the previous commit hardened the driver this was silently swallowed and the test vacuously printed NO_RACE; now it failed the flaky check as SEED_FAILED: https://github.com/ClickHouse/ClickHouse/actions/runs/29428630429/job/87398275184?pr=106525 ClickHouse#106525 Re-verified all driver paths with a stub `clickhouse` handling the `client` subcommand: clean run -> NO_RACE (exit 0), race error -> RACE_DETECTED (exit 0), unrelated error -> WORKER_FAILED (exit 1). Co-Authored-By: Claude Fable 5 <[email protected]>
The churn is part of the test's contract - it is what keeps the /uuid children list volatile and widens the eviction window - but its client failures were redirected to /dev/null and ignored, so a driver whose churn queries stopped working would still report NO_RACE after silently dropping the very stressor that makes the race reproducible. Handle churn client failures like victim ones: record the output and fail the worker and the driver (WORKER_FAILED, exit 1). No race detection is needed in churn: IF NOT EXISTS/IF EXISTS make its statements no-ops instead of errors when the race hides the entity. Verified with a stub clickhouse-client failing only churn_* queries: the driver now reports WORKER_FAILED (exit 1) instead of NO_RACE; the clean, race-detection and victim-unexpected-error paths are unchanged. ClickHouse#106525 (comment) Co-Authored-By: Claude Fable 5 <[email protected]>
This was referenced Jul 17, 2026
clickhouse-gh Bot
pushed a commit
that referenced
this pull request
Jul 17, 2026
…rage race that evicted a just-created entity (UNKNOWN_ROLE)
clickhouse-gh Bot
added a commit
that referenced
this pull request
Jul 17, 2026
Backport #106525 to 26.6: Add regression test for ReplicatedAccessStorage race that evicted a just-created entity (UNKNOWN_ROLE)
1 task done
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
…in the test The victim chain does by-name lookups of three just-created entities (settings profile, role, user), and the ReplicatedAccessStorage race is generic across entity types, but the detection matched only UNKNOWN_ROLE. If the race hit the profile lookup first, the multiquery failed with THERE_IS_NO_PROFILE before ever reaching the role reference and the iteration was silently retried, so a buggy build could print NO_RACE. Match UNKNOWN_ROLE, THERE_IS_NO_PROFILE, UNKNOWN_USER and the generic "There is no" text from IAccessStorage::throwNotFound instead. ClickHouse#106525 (comment) Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
Two review findings on the in-container driver: 1. `local w=$1 name="race_$w"` dies under `set -u` with "w: unbound variable": bash expands the whole `local` command line before performing any of its assignments. Every victim worker died before its first iteration, and since a bare `wait` discards worker exit statuses, the driver still printed `NO_RACE` - the test passed without issuing a single victim query. Split the declarations and wait on each collected worker PID, turning nonzero worker exits into a driver failure (`WORKER_FAILED`, exit 1). 2. The detection `case` silently retried every client failure other than the targeted not-found errors until timeout. Now a clean success continues the loop, the specific race detections stop it, and any other nonzero client result fails the worker and the driver, so the test cannot pass while never exercising the intended path. Also fail the driver if seeding the profiles fails (`SEED_FAILED`). Verified with a stub clickhouse-client: clean run -> NO_RACE (exit 0), race errors (UNKNOWN_ROLE / THERE_IS_NO_PROFILE) -> RACE_DETECTED (exit 0), unrelated error -> WORKER_FAILED (exit 1), failing seed -> SEED_FAILED (exit 1). ClickHouse#106525 (comment) ClickHouse#106525 (comment) Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
The integration-test containers mount the server binary at /usr/bin/clickhouse and have no clickhouse-client symlink, so every client call in the driver failed with "clickhouse-client: command not found". Before the previous commit hardened the driver this was silently swallowed and the test vacuously printed NO_RACE; now it failed the flaky check as SEED_FAILED: https://github.com/ClickHouse/ClickHouse/actions/runs/29428630429/job/87398275184?pr=106525 ClickHouse#106525 Re-verified all driver paths with a stub `clickhouse` handling the `client` subcommand: clean run -> NO_RACE (exit 0), race error -> RACE_DETECTED (exit 0), unrelated error -> WORKER_FAILED (exit 1). Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
The churn is part of the test's contract - it is what keeps the /uuid children list volatile and widens the eviction window - but its client failures were redirected to /dev/null and ignored, so a driver whose churn queries stopped working would still report NO_RACE after silently dropping the very stressor that makes the race reproducible. Handle churn client failures like victim ones: record the output and fail the worker and the driver (WORKER_FAILED, exit 1). No race detection is needed in churn: IF NOT EXISTS/IF EXISTS make its statements no-ops instead of errors when the race hides the entity. Verified with a stub clickhouse-client failing only churn_* queries: the driver now reports WORKER_FAILED (exit 1) instead of NO_RACE; the clean, race-detection and victim-unexpected-error paths are unchanged. ClickHouse#106525 (comment) Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
…ace_condition Add regression test for ReplicatedAccessStorage race that evicted a just-created entity (UNKNOWN_ROLE)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes: #106521
Related: #107097
Adds a regression test for a TOCTOU race in
ReplicatedAccessStoragethat could temporarily make a just-created access entity unresolvable by name.ZooKeeperReplicator::refreshEntities(all=false), run by the background watch thread, read the/uuidchildren list viagetChildrenWatchwithout holdingmutex, and only then took the lock to callmemory_storage.removeAllExcept(snapshot). A concurrentinsertEntitycreates the entity's znode first and only then takesmutexto put the entity intomemory_storage, so it could commit an entity after the snapshot was taken but before the watch thread acquired the lock.removeAllExceptthen evicted the freshly inserted entity from the local cache. Any statement resolving it by name in that window failed withThere is no role ... (UNKNOWN_ROLE), even on the same session that had just created the role (e.g.CREATE USER ... DEFAULT ROLE,CREATE QUOTA ... TO).The fix itself was merged separately via #107097 (serializing ZooKeeper read->publish sequences under
refresh_mutex) and backported to 25.8, 26.3, 26.4 and 26.5, so this PR now only adds the test.The test is a probabilistic stress regression test in
test_replicated_users: it concurrently creates access entities and immediately references them by name while background churn keeps the/uuidchildren list volatile and many seeded entities widen the eviction window. Eviction of any freshly created entity is treated as a race detection (UNKNOWN_ROLE,THERE_IS_NO_PROFILE,UNKNOWN_USER). The detection logic was validated against an unpatchedclickhouse-server26.3.4.11, where it reproducesUNKNOWN_ROLEwithin ~17s; with the fix it never fails.Originally observed as a flaky
clickhouse-backupTestRBACfailure: https://github.com/Altinity/clickhouse-backup/actions/runs/26991435518/job/79652420544Changelog category (leave one):
Documentation entry for user-facing changes
Version info
26.7.1.1081(included in26.7and later)26.6.2.77