Skip to content

Fix data race in FutureSetFromTuple - #104673

Merged
mstetsyuk merged 2 commits into
masterfrom
fix-future-set-from-tuple-race
May 14, 2026
Merged

mstetsyuk merged 2 commits into
masterfrom
fix-future-set-from-tuple-race

Conversation

@mstetsyuk

@mstetsyuk mstetsyuk commented May 12, 2026 •

Copy link
Copy Markdown
Member

Linked issues

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

Fix a TOCTOU data race in FutureSetFromTuple::buildOrderedSetInplace that results in a logical error.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.5.1.650
  • Backported to: 26.4.3.21, 26.3.11.21, 26.2.19.29, 25.8.24.16

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

clickhouse-gh Bot commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3560975]

Summary: ❌

job_name test_name status info comment
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL

AI Review

Summary

This PR replaces ad-hoc hasExplicitSetElements checks in FutureSetFromTuple with callOnce-guarded fillSetElementsOnce so concurrent callers do not populate set elements twice. The synchronization direction looks correct, but the Critical Bug Fix contract is still unproven because there is no focused regression evidence that the race is actually fixed.

Tests
  • ⚠️ [src/Interpreters/PreparedSets.cpp:149] The PR claims a data-race fix, but it adds no targeted reproducer, regression test, or before/after sanitizer evidence. Please provide either:
    1. a focused stress/regression test that drives concurrent calls to FutureSetFromTuple::buildOrderedSetInplace and FutureSetFromTuple::getKeyColumns on the same object, or
    2. before/after TSAN output from the same reproducer showing the race is gone on this branch.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
    1. Add focused regression evidence (test or before/after TSAN run) that demonstrates the race fix.

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels May 12, 2026
FutureSet::Hash FutureSetFromTuple::getHash() const { return hash; }

Columns FutureSetFromTuple::getKeyColumns()
void FutureSetFromTuple::fillSetElementsOnce()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like the right synchronization direction, but we still need proof that the race is fixed.
Please add a focused regression test that exercises concurrent access to the same FutureSetFromTuple from both buildOrderedSetInplace and getKeyColumns and verifies we do not hit LOGICAL_ERROR (and ideally stays clean under TSAN).
Without that, the Critical Bug Fix contract is not verifiable.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's possible to cover that race with a test

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. I agree deterministic reproduction of this race is hard, but we still need evidence for the Critical Bug Fix contract.

Please add a focused regression/stress test that drives concurrent calls to FutureSetFromTuple::buildOrderedSetInplace and FutureSetFromTuple::getKeyColumns on the same object (ideally under TSAN), or provide before/after TSAN evidence from this reproducer. Without that, we cannot verify the race is actually fixed rather than just made less likely.

@alexey-milovidov

Copy link
Copy Markdown
Member

The FileCacheTest.SLRUFreeSpaceKeepingProtectedOnly failure on this PR is a known flaky test that was fixed in #104418. Could you please update the branch with the latest master to pick up the fix?

@clickhouse-gh

clickhouse-gh Bot commented May 12, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 84.10% +0.10%
Functions 91.10% 91.10% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 100.00% (15/15) · Uncovered code

Full report · Diff report

@mstetsyuk
mstetsyuk added this pull request to the merge queue May 14, 2026
Merged via the queue into master with commit b6844b2 May 14, 2026
322 of 326 checks passed
@mstetsyuk
mstetsyuk deleted the fix-future-set-from-tuple-race branch May 14, 2026 15:17
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label May 14, 2026
robot-clickhouse-ci-1 added a commit that referenced this pull request May 14, 2026
Cherry pick #104673 to 25.8: Fix data race in FutureSetFromTuple
robot-clickhouse-ci-1 added a commit that referenced this pull request May 14, 2026
Cherry pick #104673 to 26.2: Fix data race in FutureSetFromTuple
robot-clickhouse-ci-1 added a commit that referenced this pull request May 14, 2026
Cherry pick #104673 to 26.3: Fix data race in FutureSetFromTuple
robot-clickhouse-ci-1 added a commit that referenced this pull request May 14, 2026
Cherry pick #104673 to 26.4: Fix data race in FutureSetFromTuple
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 14, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label May 14, 2026
mstetsyuk added a commit that referenced this pull request May 15, 2026
Backport #104673 to 26.2: Fix data race in FutureSetFromTuple
mstetsyuk added a commit that referenced this pull request May 15, 2026
Backport #104673 to 26.3: Fix data race in FutureSetFromTuple
mstetsyuk added a commit that referenced this pull request May 15, 2026
Backport #104673 to 26.4: Fix data race in FutureSetFromTuple
mstetsyuk added a commit that referenced this pull request May 15, 2026
Backport #104673 to 25.8: Fix data race in FutureSetFromTuple
@watson-ch watson-ch Bot added v25.10-must-backport v25.12-must-backport v26.2-must-backport and removed pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels May 15, 2026
@watson-ch

watson-ch Bot commented May 15, 2026

Copy link
Copy Markdown

Backport labels have been automatically added based on https://github.com/ClickHouse/clickhouse-core-incidents/issues/1138

Labels added:

  • v25.8-must-backport
  • v25.10-must-backport
  • v25.12-must-backport
  • v26.2-must-backport

These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels.

@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label May 15, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label May 15, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…4673

Backport ClickHouse#104673 to 26.4: Fix data race in FutureSetFromTuple
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v25.12-must-backport v26.2-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants