Fix deadlock in ~Consumer() during rd_kafka_consumer_close()#6
Closed
azat wants to merge 1 commit intoremove-recursive-submodulesfrom
Closed
Fix deadlock in ~Consumer() during rd_kafka_consumer_close()#6azat wants to merge 1 commit intoremove-recursive-submodulesfrom
azat wants to merge 1 commit intoremove-recursive-submodulesfrom
Conversation
~Consumer() called close() which invoked rd_kafka_consumer_close() directly, bypassing rd_kafka_destroy_flags(). This meant rk_terminate was never set, so consumer_close() took the blocking path, dispatched a rebalance callback, and handle_rebalance() called rd_kafka_assign() — a synchronous cross-thread RPC to the cgrp ops queue. The reply could get purged by rd_kafka_cgrp_terminated() racing on the internal main thread, deadlocking the caller forever. Replace close() with destroy_handle() which calls rd_kafka_destroy_flags() directly — the same path librdkafka uses internally. This sets rk_terminate before calling consumer_close(), enabling the fast non-blocking path when RD_KAFKA_DESTROY_F_NO_CONSUMER_CLOSE is set. The handle stays valid in the unique_ptr during the destroy (so get_handle() works if rebalance callbacks fire), then is released to prevent double-destroy in ~KafkaHandleBase. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Ergus
approved these changes
Mar 24, 2026
Member
Author
|
I will first merge ClickHouse/ClickHouse#100612 Then, I will properly merge everything into |
Member
Author
|
This has been merged into proper branch manually - Including all missing changes |
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.
~Consumer() called close() which invoked rd_kafka_consumer_close() directly, bypassing rd_kafka_destroy_flags(). This meant rk_terminate was never set, so consumer_close() took the blocking path, dispatched a rebalance callback, and handle_rebalance() called rd_kafka_assign() — a synchronous cross-thread RPC to the cgrp ops queue. The reply could get purged by rd_kafka_cgrp_terminated() racing on the internal main thread, deadlocking the caller forever.
Replace close() with destroy_handle() which calls rd_kafka_destroy_flags() directly — the same path librdkafka uses internally. This sets rk_terminate before calling consumer_close(), enabling the fast non-blocking path when RD_KAFKA_DESTROY_F_NO_CONSUMER_CLOSE is set. The handle stays valid in the unique_ptr during the destroy (so get_handle() works if rebalance callbacks fire), then is released to prevent double-destroy in ~KafkaHandleBase.
Refs: ClickHouse/ClickHouse#100511