Repository navigation
Fix possible usage of outdated parts due to TOCTOU race for shared parts - #93022
Merged
Merged
Conversation
Contributor
|
Workflow [PR], commit [ae20578] Summary: ❌
|
Member
Author
|
Things got more complex because OPTIMIZE in the issue does not use list of parts from this snapshot, so it does nothing, and it was hard to understand It even reset list of these parts (heh) |
ahmadov
reviewed
Dec 24, 2025
Imagine the following scenario:
T1: TRUNCATE TABLE T2: OPTIMIZE TABLE
lockParts() # exclusive lock!
shared_parts_list = nullptr
getPossiblySharedVisibleDataPartsRanges()
shared_lock_holder = readLockParts() # shared lock, shared_parts_list == nullptr
auto parts = getDataPartsVectorForInternalUsage({DataPartState::Active}, *shared_lock_holder);
shared_lock_holder.reset();
lockParts() # exclusive lock
remove parts from list
shared_parts_list = nullptr
lock_holder.emplace(data_parts_mutex, /*data_=*/ nullptr); # exclusive lock!
shared_ranges_in_parts = std::make_shared<const RangesInDataParts>(parts);
shared_parts_list = std::make_shared<const DataPartsVector>(std::move(parts));
It will lead to T2 will cache outdated parts in `shared_parts_list`.
And I think this is why `01443_merge_truncate_long` started to fail
Fixes: ClickHouse#92098
Fixes: ClickHouse#85535
azat
force-pushed
the
fix-shared-parts-TOCTOU-race
branch
from
December 24, 2025 17:36
86dc699 to
ae20578
Compare
ahmadov
approved these changes
Dec 24, 2025
ahmadov
left a comment
Member
There was a problem hiding this comment.
LGTM 👍 Thanks for a quick fix!
azat
enabled auto-merge
December 24, 2025 17:50
robot-clickhouse
added a commit
that referenced
this pull request
Dec 24, 2025
… TOCTOU race for shared parts
robot-clickhouse
added a commit
that referenced
this pull request
Dec 24, 2025
… TOCTOU race for shared parts
clickhouse-gh Bot
added a commit
that referenced
this pull request
Dec 24, 2025
Backport #93022 to 25.12: Fix possible usage of outdated parts due to TOCTOU race for shared parts
clickhouse-gh Bot
added a commit
that referenced
this pull request
Dec 24, 2025
Backport #93022 to 25.11: Fix possible usage of outdated parts due to TOCTOU race for shared parts
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.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix possible usage of outdated parts due to TOCTOU race for shared parts
Imagine the following scenario:
It will lead to T2 will cache outdated parts in
shared_parts_list.And I think this is why
01443_merge_truncate_longstarted to failFixes: #92098
Fixes: #85535