You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "ShivsundarR (via GitHub)" <gi...@apache.org> on 2026/01/02 13:02:30 UTC
[PR] MINOR : Tolerate GroupIdNotFoundException in consumer when leaving a group. [kafka]
ShivsundarR opened a new pull request, #21239:
URL: https://github.com/apache/kafka/pull/21239
*What*
- Currently if a consumer/share-consumer calls `close()` before it has joined a group, then the heartbeat on close will be sent with `epoch` = -1 and the broker would return "`GroupIdNotFoundException`".
- This was causing couple of tests in `ShareConsumerTest` to be flaky if the heartbeat to join the group was sent with `epoch` = -1.
- Since this can occur in real scenarios as well, it would be better to tolerate this exception while we are leaving the group so that the consumer can close cleanly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR : Tolerate GroupIdNotFoundException in consumer when leaving a group. [kafka]
Posted by "AndrewJSchofield (via GitHub)" <gi...@apache.org>.
AndrewJSchofield merged PR #21239:
URL: https://github.com/apache/kafka/pull/21239
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR : Tolerate GroupIdNotFoundException in consumer when leaving a group. [kafka]
Posted by "AndrewJSchofield (via GitHub)" <gi...@apache.org>.
AndrewJSchofield commented on PR #21239:
URL: https://github.com/apache/kafka/pull/21239#issuecomment-3705799196
@ShivsundarR I still get a failure of `testSubscribeOnInvalidTopicThrowsInvalidTopicException` even with this patch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR : Tolerate GroupIdNotFoundException in consumer when leaving a group. [kafka]
Posted by "ShivsundarR (via GitHub)" <gi...@apache.org>.
ShivsundarR commented on PR #21239:
URL: https://github.com/apache/kafka/pull/21239#issuecomment-3705977710
Thanks @AndrewJSchofield, I was using the incorrect state for the check, it should actually be `MemberState.UNSUBSCRIBED`, since we move from `MemberState.LEAVING` to `MemberState.UNSUBSCRIBED` after sending a leave request.
I have made this change now, and ran the test locally for 100 times and did not get a flake.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR : Tolerate GroupIdNotFoundException in consumer when leaving a group. [kafka]
Posted by "AndrewJSchofield (via GitHub)" <gi...@apache.org>.
AndrewJSchofield commented on code in PR #21239:
URL: https://github.com/apache/kafka/pull/21239#discussion_r2661347415
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractHeartbeatRequestManager.java:
##########
@@ -432,6 +432,23 @@ private void onErrorResponse(final R response, final long currentTimeMs) {
"subscribe. " + errorMessage));
break;
+ case GROUP_ID_NOT_FOUND:
+ // If the group doesn't exist (e.g., member never joined due to InvalidTopicException),
+ // GROUP_ID_NOT_FOUND should be ignored - the leave is effectively complete.
+ // When a leave heartbeat (epoch=-1) is sent, the state transitions synchronously
+ // from LEAVING to UNSUBSCRIBED in onHeartbeatRequestGenerated() before the request is sent.
+ if (membershipManager().state() == MemberState.UNSUBSCRIBED) {
+ logger.info("{} received GROUP_ID_NOT_FOUND for group {} while unsubscribed. " +
+ "Not treating as fatal since consumer is leaving group.",
+ heartbeatRequestName(), membershipManager().groupId());
+ membershipManager().onHeartbeatRequestSkipped();
+ } else {
+ // Else, this is a fatal error, we should throw it and transition to fatal state.
+ logger.error("{} failed due to unexpected error {}: {}",
Review Comment:
nit: The following `logger.error` is identical but on a single line. Please change this to a single line also.
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractHeartbeatRequestManager.java:
##########
@@ -432,6 +432,23 @@ private void onErrorResponse(final R response, final long currentTimeMs) {
"subscribe. " + errorMessage));
break;
+ case GROUP_ID_NOT_FOUND:
+ // If the group doesn't exist (e.g., member never joined due to InvalidTopicException),
+ // GROUP_ID_NOT_FOUND should be ignored - the leave is effectively complete.
+ // When a leave heartbeat (epoch=-1) is sent, the state transitions synchronously
+ // from LEAVING to UNSUBSCRIBED in onHeartbeatRequestGenerated() before the request is sent.
+ if (membershipManager().state() == MemberState.UNSUBSCRIBED) {
+ logger.info("{} received GROUP_ID_NOT_FOUND for group {} while unsubscribed. " +
+ "Not treating as fatal since consumer is leaving group.",
Review Comment:
I would remove the "Not treating as fatal since consumer is leaving group.". There's no sense in using "fatal" in an information log line. This is nothing to worry about in the slightest.
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractHeartbeatRequestManager.java:
##########
@@ -432,6 +432,23 @@ private void onErrorResponse(final R response, final long currentTimeMs) {
"subscribe. " + errorMessage));
break;
+ case GROUP_ID_NOT_FOUND:
+ // If the group doesn't exist (e.g., member never joined due to InvalidTopicException),
+ // GROUP_ID_NOT_FOUND should be ignored - the leave is effectively complete.
+ // When a leave heartbeat (epoch=-1) is sent, the state transitions synchronously
+ // from LEAVING to UNSUBSCRIBED in onHeartbeatRequestGenerated() before the request is sent.
+ if (membershipManager().state() == MemberState.UNSUBSCRIBED) {
+ logger.info("{} received GROUP_ID_NOT_FOUND for group {} while unsubscribed. " +
+ "Not treating as fatal since consumer is leaving group.",
+ heartbeatRequestName(), membershipManager().groupId());
+ membershipManager().onHeartbeatRequestSkipped();
+ } else {
+ // Else, this is a fatal error, we should throw it and transition to fatal state.
+ logger.error("{} failed due to unexpected error {}: {}",
+ heartbeatRequestName(), error, errorMessage);
+ handleFatalFailure(error.exception(errorMessage));
+ }
+ break;
Review Comment:
nit: Let's have a blank line following the break to match the other cases in this switch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org