Repository navigation
Fix possible crash during shutting down background pools - #81473
Merged
Merged
Conversation
Contributor
Member
|
I've also preventively reverted #81481 |
azat
marked this pull request as draft
June 8, 2025 08:37
azat
force-pushed
the
fix-bg-pool-shutdown
branch
from
June 8, 2025 21:57
a0f20c2 to
3dadc61
Compare
azat
force-pushed
the
fix-bg-pool-shutdown
branch
from
June 9, 2025 07:19
3dadc61 to
6404951
Compare
azat
force-pushed
the
fix-bg-pool-shutdown
branch
3 times, most recently
from
June 9, 2025 09:42
c713396 to
3cf8ad5
Compare
azat
marked this pull request as ready for review
June 9, 2025 11:16
Member
Author
Add a unit test |
serxa
approved these changes
Jun 9, 2025
There are multiple issues in the BackgroundSchedulePool, due to BackgroundSchedulePoolTaskInfo holds raw reference to the pool, which is wrong for multiple reasons, and there is no way to fix it properly because we do not track all tasks in the BackgroundSchedulePool (even inactive), and eventually this may lead to crash (during server shutdown of background pools). There were multiple attempts to fix it: - ClickHouse#80069 - It introduces deadlock [1] - And a UB due to usuing foreach and erase inside - But the main reason is that it does not fix all the issues, i.e. active() after the pool has been destroyed still leads to UB [1]: https://s3.amazonaws.com/clickhouse-test-reports/PRs/81398/c07d7ee6eb7c3d1d0c65649ea4b57f881571599c//stress_test_amd_debug/gdb.log - previous version of this patch set - Introduces lock order inversion [2] and [3], since I tried the apprach that ClickHouse#80069 was been using - clean all jobs in the destructor of the pool - But, when it came to the test I found out that while clickhouse-server may use this pool correctly it is hard to do so without knowing how to, so after this I converted the raw reference of the BackgroundSchedulePool in BackgroundSchedulePoolTaskInfo to weak_ptr, to avoid any UBs [2]: https://s3.amazonaws.com/clickhouse-test-reports/PRs/81473/a0f20c2ad7efc19d698ceb0281e0a122ebef457e//stress_test_amd_tsan/stderr.log [3]: https://s3.amazonaws.com/clickhouse-test-reports/PRs/81473/6404951bfb5156b00a4aa5302d1c0ca8272a2c56//stress_test_amd_tsan/stderr.log Also I've encapsulated the BackgroundSchedulePool and BackgroundSchedulePoolTaskInfo more, to avoid any misuse.
azat
force-pushed
the
fix-bg-pool-shutdown
branch
from
June 9, 2025 13:39
3cf8ad5 to
2920d33
Compare
Member
Author
|
@alexey-milovidov changes requests blocks from merging, PTAL |
azat
enabled auto-merge
June 9, 2025 20:00
alexey-milovidov
approved these changes
Jun 13, 2025
Member
Member
I think with unit tests it's only possible to check that they were added. Or how do you suggest validating that a new unit test covers a problem?
|
Member
Yes - added or modified unit test - fulfill the BugFix check. |
Member
Ok, and we should fix it. If it's not yours, ask your team lead, @alesapin |
Member
Author
This is some issue with LSan itself I think, if someone will have a reproducer I will take a look, post it please to this issue - #81858 |
azat
added a commit
to azat/ClickHouse
that referenced
this pull request
Jul 15, 2025
After ClickHouse#81473 it is possible that BackgroundSchedulePool threads will be joined from some task, due to weak_ptr, fix this, by adding separate method for shutdown that will be called explicitly.
pull Bot
pushed a commit
to Lobinson1/ClickHouse
that referenced
this pull request
Aug 21, 2026
…lease The Upgrade check starts a previous release and then upgrades to the build under test. get_previous_release_tag.py picks that baseline, and it could silently pick one many releases too old. find_previous_release skipped any release below server_version whose metadata did not yet list an uploaded clickhouse-common-static_*.deb, returning (False, None). The caller's unbounded `while not found:` then advanced to the next page. The /releases endpoint is ordered by created_at, not by version, so later pages hold only older releases, and nothing re-checked that the answer was the newest release below the version under test. The only diagnostic on the skip path was a logger.debug under basicConfig(level=INFO), and the resolver still exited 0 with a well-formed tag, so upgrade_runner.sh's `[ $? -ne 0 ]` guard passed. On PR ClickHouse#114376 commit e1cb0de this resolved v25.1.4.53 as the baseline for a 26.8.1.1 build; that 25.1 server then aborted during shutdown on a use-after-free that 2920d33 (ClickHouse#81473) already fixed, so the job reported `Received signal 6` and `Cannot start clickhouse-server` for a reason unrelated to the PR. Two commits earlier the same PR resolved v26.7.3.19 correctly with a byte-identical resolver, and 4 of 47 recent Upgrade-check runs used a wrong baseline. Master and every active release branch already carry the weak_ptr fix, so no C++ change is needed here. Select the baseline by version alone and resolve from the first page or raise. Page 1 holds 100 releases and its newest entry below 26.8.1.1 already equals the maximum over all 700, so the walk was never needed on the healthy path; a page-1 miss means the response was degraded, which is exactly when continuing is wrong. A page cap was rejected because page 2 can supply a stale candidate before any cap fires. Removing the asset filter from selection changes one failure mode deliberately: a partially published release that is genuinely the newest below the build is now selected and fails at the download boundary with `Download script failed`, instead of being skipped in favour of an older one. Validation already fails closed there - download_packages raises for a required prefix absent from the release metadata - so this trades a narrow window for a loud, attributable failure instead of a silent wrong-baseline run. Adds ci/tests/test_get_previous_release_tag.py; the resolver had no tests. Three of the six cases fail on the previous code, returning the exact stale tags observed in CI. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114376&sha=e1cb0dee5e9bd972e9bbbdd8cd8d971ad1e39ee1&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29
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 to CHANGELOG.md):
Fix possible crash during shutting down background pools (
background_.*pool_size)There are multiple issues in the BackgroundSchedulePool, due to
BackgroundSchedulePoolTaskInfo holds raw reference to the pool, which is
wrong for multiple reasons, and there is no way to fix it properly
because we do not track all tasks in the BackgroundSchedulePool (even
inactive), and eventually this may lead to crash (during server
shutdown of background pools).
There were multiple attempts to fix it:
Prevent use-after-free in BackgroundSchedulePool::TaskInfo by tracking pool shutdown #80069
active() after the pool has been destroyed still leads to UB
previous version of this patch set
Introduces lock order inversion 2 and 3, since I tried the
apprach that Prevent use-after-free in BackgroundSchedulePool::TaskInfo by tracking pool shutdown #80069 was been using - clean all jobs in the
destructor of the pool
But, when it came to the test I found out that while
clickhouse-server may use this pool correctly it is hard to do so
without knowing how to, so after this I converted the
raw reference of the BackgroundSchedulePool in
BackgroundSchedulePoolTaskInfo to weak_ptr, to avoid any UBs
Also I've encapsulated the BackgroundSchedulePool and
BackgroundSchedulePoolTaskInfo more, to avoid any misuse.
Fixes: #80066 (cc @serxa @VicoWu)