Repository navigation
Fix DROP TABLE on Kafka tables hanging in rd_kafka_consumer_close - #100604
Conversation
`DROP TABLE` on Kafka engine tables can hang indefinitely when `rd_kafka_consumer_close` deadlocks during the rebalance callback. The rebalance callback calls `rd_kafka_assign` which blocks on an internal queue that is not being serviced during close. Three fixes: 1. cppkafka: respect `RD_KAFKA_DESTROY_F_NO_CONSUMER_CLOSE` flag in `Consumer::~Consumer()`. ClickHouse already sets this flag, but the destructor was ignoring it and calling `close()` anyway. 2. Add a 60-second timeout to `cleanConsumers()` in both `StorageKafka` and `StorageKafka2`, so that if consumers are stuck in-use, shutdown proceeds instead of hanging forever. 3. Remove unnecessary cleanup table in `test_kafka_consumer_hang` that creates and drops a second Kafka table with 8 consumers. The topic has no messages to drain, so this step is unnecessary and triggers the hang under MSan. Closes #100511 https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100392&sha=67f7eb5082b883fc918b13af17d67ee89ab57d2b&name_0=PR&name_1=Integration%20tests%20%28amd_msan%2C%202%2F6%29 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Workflow [PR], commit [4e2a9aa] Summary: ✅ AI ReviewSummaryThis PR adds a bounded shutdown wait in ClickHouse Rules
Final Verdict
|
…hang-test # Conflicts: # contrib/cppkafka
After the timeout in `cleanConsumers`, the code previously called `moveConsumer` unconditionally on all consumers, which could race with worker threads still holding references. For `KeeperHandlingConsumer`, this would also trigger `chassert(!isInUse())` in debug/sanitizer builds. Now skip consumers that are still in use after the timeout and log how many were skipped. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The bugfix validation runs all tests in the modified `test_batch_fast.py` against the master binary (non-MSan). Since the consumer close deadlock only reproduces under MSan, all 93 tests pass on the master binary, causing the validation to report "Failed to reproduce the bug". By reverting the test file change, the bugfix validation for integration tests won't run (no integration test files changed). The C++ fix (cppkafka + timeout in `cleanConsumers`) is the real fix and makes the test cleanup code safe regardless. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
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. |
LLVM Coverage Report
Changed lines: 82.50% (33/40) · Uncovered code |
|
Hi — this PR may need backporting to Affected code: StorageKafka::cleanConsumers and StorageKafka2::cleanConsumers — core code present in all supported branches. Why: StorageKafka::cleanConsumers has existed since the original StorageKafka.cpp file (ancient, predates all supported branches). StorageKafka2::cleanConsumers was introduced in December 2023 (commit ba55c09), also predating all supported branches. The bug (DROP TABLE hang in rd_kafka_consumer_close) affects any deployment using Kafka tables and can be triggered by network issues causing heartbeat failures during shutdown. If this should be backported, consider adding |
DROP TABLEon Kafka engine tables can hang indefinitely whenrd_kafka_consumer_closedeadlocks during the rebalance callback. The rebalance callback callsrd_kafka_assignwhich blocks on an internal queue that is not being serviced during close.Three fixes:
cppkafka: respect
RD_KAFKA_DESTROY_F_NO_CONSUMER_CLOSEflag inConsumer::~Consumer(). ClickHouse already sets this flag (inKafkaConsumer::createConsumer), but the cppkafka destructor was ignoring it and callingclose()anyway, leading to the deadlock.Timeout in
cleanConsumers: add a 60-second timeout tocleanConsumers()in bothStorageKafkaandStorageKafka2, so that if consumers are stuck in-use, shutdown proceeds instead of hanging forever.Test fix: remove unnecessary cleanup table in
test_kafka_consumer_hangthat creates and drops a second Kafka table with 8 consumers. The topic has no messages to drain, so this step is unnecessary and triggers the hang under MSan.CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100392&sha=67f7eb5082b883fc918b13af17d67ee89ab57d2b&name_0=PR&name_1=Integration%20tests%20%28amd_msan%2C%202%2F6%29
#100392
Closes #100511
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
DROP TABLEon Kafka engine tables potentially hanging indefinitely due to a deadlock inrd_kafka_consumer_close.Documentation entry for user-facing changes
Version info
26.5.1.88