chia7712 commented on PR #16974: URL: https://github.com/apache/kafka/pull/16974#issuecomment-2308544944
> 2. background thread transitions to LEAVING 2.1 the next run of the background thread should poll the HB manager and generate a request Sorry that I want to understand the root cause before reviewing. We had a discussion before (https://issues.apache.org/jira/browse/KAFKA-15305), and I assumed that step_2 and step_2.1 are executed in the same run. ``` void runOnce() { // step_2: background thread transitions to LEAVING by handling UnsubscribeEvent processApplicationEvents(); final long currentTimeMs = time.milliseconds(); final long pollWaitTimeMs = requestManagers.entries().stream() .filter(Optional::isPresent) .map(Optional::get) // step_2.1: generate a LEAVE request as the state is `LEAVING` now .map(rm -> rm.poll(currentTimeMs)) .map(networkClientDelegate::addAll) .reduce(MAX_POLL_TIMEOUT_MS, Math::min); networkClientDelegate.poll(pollWaitTimeMs, currentTimeMs); ... } ``` I guess the scenario (step 2.1: the next run) you described is caused by `ConsumerRebalanceListener`, right? The `ConsumerRebalanceListener` must be executed by application thread, so background thread can not change the state to `LEAVING` before polling `RequestManager` if application thread does not execute `ConsumerRebalanceListener` in time. -- 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