Fix crash in clearDirectory on concurrent removal of delete_tmp_ directory#94892
Merged
alexey-milovidov merged 2 commits intoClickHouse:masterfrom Jan 30, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a crash during ReplicatedMergeTree startup caused by concurrent directory removal. When clearOldTemporaryDirectories (running in AttachThread) and loadOutdatedDataParts both attempt to delete the same delete_tmp_* directory, the fallback fs::remove_all can throw a filesystem_error when files disappear mid-traversal, leading to termination.
Changes:
- Added exception handling in
clearDirectoryto gracefully handle concurrent directory removal by catchingfilesystem_errorwithno_such_file_or_directoryerror code
Contributor
|
Workflow [PR], commit [fbc2f28] Summary: ❌
|
Contributor
tiandiwonder
left a comment
There was a problem hiding this comment.
really good analysis!
Contributor
There was a problem hiding this comment.
We need to handle it too.
| try | ||
| { | ||
| can_remove_description.emplace(can_remove_callback()); | ||
| disk->removeSharedRecursive( |
Contributor
There was a problem hiding this comment.
we need to handle it too.
Contributor
Author
There was a problem hiding this comment.
Done. Applied the same catch to both call sites.
tiandiwonder
approved these changes
Jan 29, 2026
robot-ch-test-poll2
added a commit
that referenced
this pull request
Jan 30, 2026
Cherry pick #94892 to 25.3: Fix crash in clearDirectory on concurrent removal of delete_tmp_ directory
robot-clickhouse
added a commit
that referenced
this pull request
Jan 30, 2026
…moval of delete_tmp_ directory
robot-ch-test-poll2
added a commit
that referenced
this pull request
Jan 30, 2026
Cherry pick #94892 to 25.8: Fix crash in clearDirectory on concurrent removal of delete_tmp_ directory
robot-clickhouse
added a commit
that referenced
this pull request
Jan 30, 2026
…moval of delete_tmp_ directory
robot-ch-test-poll2
added a commit
that referenced
this pull request
Jan 30, 2026
Cherry pick #94892 to 25.10: Fix crash in clearDirectory on concurrent removal of delete_tmp_ directory
robot-clickhouse
added a commit
that referenced
this pull request
Jan 30, 2026
…emoval of delete_tmp_ directory
robot-ch-test-poll2
added a commit
that referenced
this pull request
Jan 30, 2026
Cherry pick #94892 to 25.11: Fix crash in clearDirectory on concurrent removal of delete_tmp_ directory
robot-clickhouse
added a commit
that referenced
this pull request
Jan 30, 2026
…emoval of delete_tmp_ directory
robot-ch-test-poll2
added a commit
that referenced
this pull request
Jan 30, 2026
Cherry pick #94892 to 25.12: Fix crash in clearDirectory on concurrent removal of delete_tmp_ directory
robot-clickhouse
added a commit
that referenced
this pull request
Jan 30, 2026
…emoval of delete_tmp_ directory
robot-ch-test-poll2
added a commit
that referenced
this pull request
Jan 30, 2026
Cherry pick #94892 to 26.1: Fix crash in clearDirectory on concurrent removal of delete_tmp_ directory
robot-clickhouse
added a commit
that referenced
this pull request
Jan 30, 2026
…moval of delete_tmp_ directory
clickhouse-gh bot
added a commit
that referenced
this pull request
Jan 30, 2026
Backport #94892 to 26.1: Fix crash in clearDirectory on concurrent removal of delete_tmp_ directory
clickhouse-gh bot
added a commit
that referenced
this pull request
Jan 30, 2026
Backport #94892 to 25.12: Fix crash in clearDirectory on concurrent removal of delete_tmp_ directory
clickhouse-gh bot
added a commit
that referenced
this pull request
Jan 30, 2026
Backport #94892 to 25.11: Fix crash in clearDirectory on concurrent removal of delete_tmp_ directory
clickhouse-gh bot
added a commit
that referenced
this pull request
Jan 30, 2026
Backport #94892 to 25.8: Fix crash in clearDirectory on concurrent removal of delete_tmp_ directory
alexey-milovidov
added a commit
that referenced
this pull request
Mar 17, 2026
Backport #94892 to 25.3: Fix crash in clearDirectory on concurrent removal of delete_tmp_ directory
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.
During
ReplicatedMergeTreestartup,clearOldTemporaryDirectories(called fromAttachThreadwithdelete_tmp_prefix, added in #37906) can concurrently delete a directory thatloadOutdatedDataPartsis also removing viaclearDirectory. The fallbackfs::remove_allthrowsfilesystem_errorwhen files disappear mid-traversal, propagating tostd::terminate.Applied the same
catch (const fs::filesystem_error & e)pattern already used inclearOldTemporaryDirectories(MergeTreeData.cpp:3130).Fixes #94891
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes a crash during
ReplicatedMergeTreestartup caused by concurrent removal ofdelete_tmp_*directories.