fix: resolve consumer deadlock on partition rebalance when paused (#681)#736
Open
DmytroLiulchuk wants to merge 1 commit into
Open
fix: resolve consumer deadlock on partition rebalance when paused (#681)#736DmytroLiulchuk wants to merge 1 commit into
DmytroLiulchuk wants to merge 1 commit into
Conversation
1 task
bblankenship78
approved these changes
Jun 11, 2026
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.
Description
Fixes #681
When a consumer has all partitions paused, KafkaFlow starts a heartbeat background task that calls
Consume(1000)in a loop to maintain group membership. If a partition rebalance occurs during thisConsume()call, librdkafka invokes the revoke callback (configured via Confluent.Kafka's SetPartitionsRevokedHandler) synchronously on the same thread (documented behavior). The handler callsConsumerFlowManager.Stop()→StopHeartbeat(), which previously awaited the heartbeat task synchronously via_heartbeatTask.GetAwaiter().GetResult(). Since this executes on the heartbeat thread itself, the thread waits for its own completion — a deadlock.Fix: Remove the synchronous wait in
StopHeartbeat(). AfterCancel(), the heartbeat task exits naturally on the next loop iteration(while (!IsCancellationRequested) → false), releases the semaphore infinally, and the feeder unblocks.How Has This Been Tested?
Consume(1000))Checklist
[+] My code follows the style guidelines of this project
[+] I have performed a self-review of my own code
[-] I have added tests to cover my changes
[-] I have made corresponding changes to the documentation