Skip to content

Fix possible deadlock in case of exception during disks initialization#94880

Merged
alexey-milovidov merged 2 commits intoClickHouse:masterfrom
azat:fix-deadlock-on-disk-init-error
Jan 23, 2026
Merged

Fix possible deadlock in case of exception during disks initialization#94880
alexey-milovidov merged 2 commits intoClickHouse:masterfrom
azat:fix-deadlock-on-disk-init-error

Conversation

@azat
Copy link
Copy Markdown
Member

@azat azat commented Jan 22, 2026

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Fix possible deadlock in case of exception during disks initialization

In case of DiskSelector::initalize() will throw, the shutdown() will
not be called on each disk, and this will lead to possible deadlock 1
in case of local_disk_check_period_ms > 0.

This is possible in case of i.e. you create a cached disk over a regular
one, regular is created, while cached is failed, with i.e.:

Cannot wrap disk `s3_plain_rewritable` with cache layer `s3_plain_rewritable_cache`: there is no such disk (it should be initialized before cache disk).

Note: marked as Not for changelog since the problem is possible only due to misconfiguration

@azat azat requested a review from Michicosun January 22, 2026 22:21
@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh Bot commented Jan 22, 2026

Workflow [PR], commit [c481162]

Summary:

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jan 22, 2026
@Michicosun Michicosun self-assigned this Jan 22, 2026
@azat azat force-pushed the fix-deadlock-on-disk-init-error branch from 6ae9de3 to adc6f60 Compare January 23, 2026 07:03
@@ -65,6 +65,7 @@ void DiskSelector::recordDisk(const std::string & disk_name, DiskPtr disk)

void DiskSelector::initialize(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The problem was that, in the case of an exception, merge_tree_disk_selector would not be set, and during shutdown, all created disks would not be shut down.

azat added 2 commits January 23, 2026 14:25
In case of `DiskSelector::initalize()` will throw, the `shutdown()` will
not be called on each disk, and this will lead to possible deadlock [1]
in case of `local_disk_check_period_ms > 0`.

  [1]: https://pastila.nl/?00620377/1d01d6bd2c9ab94267be3e03542b8496#EjAmYc7LfcQDTePv7Knncg==GCM

This is possible in case of i.e. you create a cached disk over a regular
one, regular is created, while cached is failed, with i.e.:

    Cannot wrap disk `s3_plain_rewritable` with cache layer `s3_plain_rewritable_cache`: there is no such disk (it should be initialized before cache disk).
@azat azat force-pushed the fix-deadlock-on-disk-init-error branch from adc6f60 to c481162 Compare January 23, 2026 13:25
@azat azat added this pull request to the merge queue Jan 23, 2026
@azat azat removed this pull request from the merge queue due to a manual request Jan 23, 2026
@alexey-milovidov alexey-milovidov added this pull request to the merge queue Jan 23, 2026
Merged via the queue into ClickHouse:master with commit 425ff4e Jan 23, 2026
134 checks passed
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog 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