dajac commented on code in PR #12035:
URL: https://github.com/apache/kafka/pull/12035#discussion_r858024381


##########
streams/src/main/java/org/apache/kafka/streams/KafkaStreams.java:
##########
@@ -1498,6 +1516,37 @@ public synchronized boolean close(final Duration 
timeout) throws IllegalArgument
         return close(timeoutMs);
     }
 
+    /**
+     * Shutdown this {@code KafkaStreams} by signaling all the threads to 
stop, and then wait up to the timeout for the
+     * threads to join.
+     * @param options  contains timeout to specify how long to wait for the 
threads to shutdown, and a flag leaveGroup to
+     *                 trigger consumer leave call
+     * @return {@code true} if all threads were successfully 
stopped—{@code false} if the timeout was reached
+     * before all threads stopped
+     * Note that this method must not be called in the {@link 
StateListener#onChange(KafkaStreams.State, KafkaStreams.State)} callback of 
{@link StateListener}.
+     * @throws IllegalArgumentException if {@code timeout} can't be 
represented as {@code long milliseconds}
+     */
+    public synchronized boolean close(final CloseOptions options) throws 
IllegalArgumentException {
+        final String msgPrefix = 
prepareMillisCheckFailMsgPrefix(options.timeout, "timeout");
+        final long timeoutMs = validateMillisecondDuration(options.timeout, 
msgPrefix);
+        if (timeoutMs < 0) {
+            throw new IllegalArgumentException("Timeout can't be negative.");
+        }
+
+        if (options.leaveGroup) {
+            log.debug("Sending leave group trigger to removing instance from 
consumer group");
+            //removing instance from consumer group
+            adminClient.removeMembersFromConsumerGroup(

Review Comment:
   I do agree with 1). We should close the consumers and then remove the 
corresponding members. I wonder if we could have a subtile race condition 
though. The issue is that we need to known the member id in order to remove it 
and we have to get it with `KafkaConsumer#groupMetadata` before calling 
`KafkaConsumer#close`. I wonder if we could have cases where the member id 
changes between `KafkaConsumer#groupMetadata` and `KafkaConsumer#close`. That 
must be rare but seems possible if we are unlucky. What do you think?



-- 
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-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to