{{ message }}
Repository navigation
MINOR: Stop the heartbeat thread when it fails with a fenced instance id - #23898
Open
ethanresnick wants to merge 1 commit into
Open
ethanresnick wants to merge 1 commit into
ethanresnick wants to merge 1 commit into
Conversation
When a heartbeat gets FENCED_INSTANCE_ID, the heartbeat thread sets its failure cause. Its loop then disables the thread and waits on the coordinator monitor. The thread does not exit. The next AbstractCoordinator.pollHeartbeat call sees the failure, sets heartbeatThread to null, and throws the cause. It does not close the thread. A later close() calls closeHeartbeatThread(), which finds a null reference and returns. So the thread "kafka-coordinator-heartbeat-thread | <group>" waits until the JVM exits. An application that recreates consumers after this error collects one such thread per consumer. The other fatal heartbeat errors (authentication, group authorization, interrupt, unexpected errors) leave the run loop, so those threads end. Fix: pollHeartbeat now closes the failed thread before it drops the reference. pollHeartbeat already holds the coordinator monitor, and HeartbeatThread.close() sets the closed flag and notifies that monitor. The thread wakes up, sees that it is closed, and returns. pollHeartbeat does not join the thread, so it does not block. Test: testHeartbeatRequestWithFencedInstanceIdException now closes the coordinator after the fenced error and waits for the heartbeat thread to stop. Without the fix, the thread is still alive after 2 seconds and the test fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

When a heartbeat gets
FENCED_INSTANCE_ID, the heartbeat thread setsits failure cause. Its loop then disables the thread and waits on the
coordinator monitor. The thread does not exit.
The next
AbstractCoordinator.pollHeartbeatcall sees the failure, setsheartbeatThreadto null, and throws the cause. It does not close thethread. A later
close()callscloseHeartbeatThread(), which finds anull reference and returns. So the thread
kafka-coordinator-heartbeat-thread | <group>waits until the JVM exits.An application that recreates consumers after this error collects one
such thread per consumer.
The other fatal heartbeat errors (authentication, group authorization,
interrupt, unexpected errors) leave the run loop, so those threads end.
This change makes
pollHeartbeatclose the failed thread before itdrops the reference.
pollHeartbeatalready holds the coordinatormonitor, and
HeartbeatThread.close()sets the closed flag and notifiesthat monitor. The thread wakes up, sees that it is closed, and returns.
pollHeartbeatdoes not join the thread, so it does not block.Testing:
testHeartbeatRequestWithFencedInstanceIdExceptionnow closesthe coordinator after the fenced error and waits up to 2 seconds for the
heartbeat thread to stop. Without the fix, this test fails because the
thread is still alive. With the fix, it passes.
AbstractCoordinatorTest,EagerConsumerCoordinatorTest,CooperativeConsumerCoordinatorTest, andKafkaConsumerTestpass.I ran the tests at trunk commit f568b7b. There,
AbstractCoordinator.javaand
BaseHeartbeatThread.javaare the same as on current trunk.AbstractCoordinatorTest.javadiffers only by the KAFKA-20858 rename inits setup (
SubscriptionStatetoConsumerSubscriptionState).Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com
🤖 Generated with Claude Code