Repository navigation
Fix FileCache shutdown deadlock caused by DatabaseCatalog exceptions - #101612
Conversation
| SHUTDOWN(log, "common executor", common_executor, wait()); | ||
|
|
||
| /// Deactivate FileCache background threads before shutting down the database catalog. | ||
| /// DatabaseCatalog::shutdown() can throw (e.g. ZooKeeper timeout in replicated DDL worker). |
There was a problem hiding this comment.
Why not just put DatabaseCatalog::shutdown() into try-catch? There can be other things which are good to properly shutdown
There was a problem hiding this comment.
Just using try-catch isn't enough because the catalog may partially-shutdown, and FileCache threads can still deadlock when accessing half-destroyed tables.
There was a problem hiding this comment.
Where exactly the deadlock happens? I do not see FileCache in stacktraces on the ci report linked in description https://s3.amazonaws.com/clickhouse-test-reports/PRs/100543/47354faba96b66dfb0a75ac61efa53e45ca1b4e1/stress_test_arm_asan_ubsan_s3/gdb.log
There was a problem hiding this comment.
CacheMetadata::downloadThreadFunc threads shown in the GDB log are FileCache's background threads. They appear in the gdb.log as follows:
182 "ThreadPool" threads (LWP 468958-468963, etc.) stuck in CacheMetadata::downloadThreadFunc on GlobalThreadPool, e.g. Thread 293 (LWP 468958):
#8 DB::CacheMetadata::downloadThreadFunc at Metadata.cpp:776
#9 DB::CacheMetadata::startup()::$_0::operator() at Metadata.cpp:944
#13 ThreadFromGlobalPoolImpl<...> at ThreadPool.h:312
#20 ThreadPoolImpl<...>::ThreadFromThreadPool::worker at ThreadPool.cpp:809
These threads are waiting on a condition variable and will never finish because deactivateBackgroundOperations() was skipped, which prevents GlobalThreadPool::shutdown() from completing.
|
Workflow [PR], commit [2635903] Summary: ✅ AI ReviewSummaryThis PR fixes a real shutdown deadlock risk by moving ClickHouse Rules
Final Verdict
|
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
|
Upgrade check (amd_release) "There is no cache by name: cached_s3" |
| LOG_TRACE(log, "Shutting down caches"); | ||
| for (const auto & cache_data : FileCacheFactory::instance().getUniqueInstances()) | ||
| cache_data->cache->deactivateBackgroundOperations(); | ||
| FileCacheFactory::instance().clear(); |
There was a problem hiding this comment.
The upgrade check fails because of FileCacheFactory::instance().clear();, we should not do this until tables are shutdown.
There was a problem hiding this comment.
Sorry about that, I missed this case. Will fix by moving FileCacheFactory::instance().clear() after DatabaseCatalog::shutdown().
Head branch was pushed to by a user without write access
|
The |
…o fix-shutdown-deadlock-filecache
…o fix-shutdown-deadlock-filecache
LLVM Coverage Report
Changed lines: 100.00% (18/18) | lost baseline coverage: 1 line(s) · Uncovered code |
|
@kssenii All checks passed. PTAL, thanks. |
|
Hi — this PR may need backporting to Affected code: Why: This fixes a server shutdown deadlock triggered when If this should be backported, consider adding |
During server shutdown, a deadlock can occur in
GlobalThreadPool::shutdown()because FileCache background threads remain stuck in the thread pool. This happens whenDatabaseCatalog::shutdown()throws an exception (e.g., ZooKeeper/Keeper timeout in replicated DDL worker), causingdeactivateBackgroundOperations()to be skipped.CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100543&sha=47354faba96b66dfb0a75ac61efa53e45ca1b4e1&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%2C%20s3%29
#100543
The timeline confirms:
Changelog category (leave one):