Skip to content

Fix TSan data race in Keeper AuthID between preprocess and commit - #100396

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-keeper-tsan-auth-race
Mar 24, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix-keeper-tsan-auth-race

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Mar 22, 2026 •

Copy link
Copy Markdown
Member

The AddAuthDelta stores a shared_ptr<AuthID> that is shared between the delta and the uncommitted state. During commit, the code was move-constructing from this shared AuthID via std::move(*operation.auth_id), which could race with a concurrent preprocess call reading the same AuthID through uncommitted_state.session_and_auth without holding auth_mutex.

Fix by copying instead of moving.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=3134af4b1eeebf8773015eb04eb1aa1a80bd2f17&name_0=MasterCI&name_1=Integration%20tests%20%28amd_tsan%2C%206%2F6%29

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.4.1.191 (included in 26.4 and later)
  • Backported to: 25.8.26.6

The `AddAuthDelta` stores a `shared_ptr<AuthID>` that is shared between
the delta and the uncommitted state. During `commit`, the code was
move-constructing from this shared `AuthID` via `std::move(*operation.auth_id)`,
which could race with a concurrent `preprocess` call reading the same
`AuthID` through `uncommitted_state.session_and_auth` without holding
`auth_mutex`.

Fix by copying instead of moving.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=3134af4b1eeebf8773015eb04eb1aa1a80bd2f17&name_0=MasterCI&name_1=Integration%20tests%20%28amd_tsan%2C%206%2F6%29

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Mar 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9785e40]

Summary: ✅


AI Review

Summary

This PR fixes a real TSan race in Keeper auth handling by replacing a move from shared AuthID state with a copy during AddAuthDelta commit in KeeperStorage. The change is small, targeted, and correctly addresses the race scenario between preprocess and commit without altering external behavior.

ClickHouse Rules

Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅

Final Verdict

  • Status: ✅ Approve

@clickhouse-gh

clickhouse-gh Bot commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.90% 83.90% +0.00%
Functions 24.70% 24.70% +0.00%
Branches 76.50% 76.60% +0.10%

PR changed lines: PR changed-lines coverage: 100.00% (4/4, 0 noise lines excluded)
Diff coverage report
Uncovered code

@alexey-milovidov
alexey-milovidov merged commit f14497c into master Mar 24, 2026
148 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-keeper-tsan-auth-race branch March 24, 2026 11:21
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 24, 2026
alexey-milovidov added a commit that referenced this pull request Jul 1, 2026
Backport #100396 to 25.8: Fix TSan data race in Keeper AuthID between preprocess and commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants