Repository navigation
Catch exceptions from assign/unassign in handle_rebalance - #7
Merged
alexey-milovidov merged 2 commits intoApr 28, 2026
Merged
Conversation
handle_rebalance is called from rebalance_proxy, a C callback registered with librdkafka. The assign() and unassign() calls inside it can now throw HandleException when rd_kafka_assign() times out (instead of blocking forever). Throwing from a C callback is undefined behavior. Wrap assign() and unassign() in try/catch and route timeout errors through the existing rebalance_error_callback_, which the application already handles. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
alexey-milovidov
added a commit
to ClickHouse/ClickHouse
that referenced
this pull request
Mar 30, 2026
…gn wait When a Kafka consumer experiences a heartbeat error followed by a rebalance (e.g. after broker becomes temporarily unreachable), DROP TABLE can hang indefinitely. The root cause is inside librdkafka: rd_kafka_assign(), called from the rebalance callback during poll_batch(), sends an op to the consumer-group thread and waits with RD_POLL_INFINITE. If the cgrp thread is blocked waiting for the coordinator, poll_batch() never returns, making pipeline cancellation impossible regardless of the cancel callback. This updates both contrib/librdkafka and contrib/cppkafka: - librdkafka: replace RD_POLL_INFINITE with 30s timeout in rd_kafka_assign0 (ClickHouse/librdkafka#18) - cppkafka: catch HandleException from assign/unassign in handle_rebalance to prevent throwing from a C callback (ClickHouse/cppkafka#7) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 task
`handle_rebalance` is called from `rebalance_proxy`, a C callback. `assign`/`unassign` can throw not only `HandleException` (e.g. on `rd_kafka_assign` timeout) but also other exceptions such as allocation failures while converting `TopicPartitionList`. Letting any exception escape a C callback is undefined behavior. Catch `std::exception` and `...` in addition to `HandleException`, routing errors through the existing `rebalance_error_callback_` with `RD_KAFKA_RESP_ERR__FAIL` as a generic error code. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
alexey-milovidov
added a commit
to ClickHouse/ClickHouse
that referenced
this pull request
Apr 29, 2026
Bump `contrib/cppkafka` and `contrib/librdkafka` to the heads of their ClickHouse release branches now that the dependent fork PRs are merged: - cppkafka: bump to merge of ClickHouse/cppkafka#7 (Catch exceptions from `assign`/`unassign` in `handle_rebalance`). - librdkafka: bump to merge of ClickHouse/librdkafka#18 (Use bounded timeout in `rd_kafka_assign0` instead of `RD_POLL_INFINITE`) and ClickHouse/librdkafka#17 (Fix use-after-free in consumer lag timer). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
…gn wait When a Kafka consumer experiences a heartbeat error followed by a rebalance (e.g. after broker becomes temporarily unreachable), DROP TABLE can hang indefinitely. The root cause is inside librdkafka: rd_kafka_assign(), called from the rebalance callback during poll_batch(), sends an op to the consumer-group thread and waits with RD_POLL_INFINITE. If the cgrp thread is blocked waiting for the coordinator, poll_batch() never returns, making pipeline cancellation impossible regardless of the cancel callback. This updates both contrib/librdkafka and contrib/cppkafka: - librdkafka: replace RD_POLL_INFINITE with 30s timeout in rd_kafka_assign0 (ClickHouse/librdkafka#18) - cppkafka: catch HandleException from assign/unassign in handle_rebalance to prevent throwing from a C callback (ClickHouse/cppkafka#7) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
Bump `contrib/cppkafka` and `contrib/librdkafka` to the heads of their ClickHouse release branches now that the dependent fork PRs are merged: - cppkafka: bump to merge of ClickHouse/cppkafka#7 (Catch exceptions from `assign`/`unassign` in `handle_rebalance`). - librdkafka: bump to merge of ClickHouse/librdkafka#18 (Use bounded timeout in `rd_kafka_assign0` instead of `RD_POLL_INFINITE`) and ClickHouse/librdkafka#17 (Fix use-after-free in consumer lag timer). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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.
Summary
handle_rebalanceis called fromrebalance_proxy, a C callback registered with librdkafka. Theassign()andunassign()calls inside it can now throwHandleExceptionwhenrd_kafka_assign()times out (see ClickHouse/librdkafka#18) instead of blocking forever. Throwing from a C callback is undefined behavior.Wrap
assign()andunassign()in try/catch and route timeout errors through the existingrebalance_error_callback_, which the application already handles.