Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-17403

New consumer may not send leave group on race condition on network thread run & close

    XMLWordPrintableJSON

Details

    Description

      When closing a consumer, we call:

      1. releaseAssignmentAndLeaveGroup, which ends up updating the state machine to  LEAVING. This will make that, on the next call to HeartbeatRequestManager.poll, a request to leave will be generated and added to the network layer.
      2. close the network thread (applicationEventHandler.close). This will make sure it sends all unsent request that have been already added to the network thread

      If the releaseAssignmentAndLeaveGroup times out (most common case would be close(0)), the flow moves into step 2, which will stop polling all managers. If we make it to that point (https://github.com/apache/kafka/blob/61a661ec5e627217e8b4e4c009d65ee0e0e938ba/clients/src/main/java/org/apache/kafka/clients/consumer/internals/ConsumerNetworkThread.java#L281) from the app thread, before the background thread has the chance to poll the HB manager LEAVING (https://github.com/apache/kafka/blob/61a661ec5e627217e8b4e4c009d65ee0e0e938ba/clients/src/main/java/org/apache/kafka/clients/consumer/internals/ConsumerNetworkThread.java#L142), the request to leave will never be added to the network layer to be sent. 

      Seems to me that we should ensure that the HBmanager implements the pollOnClose and sends the leave request if the state == LEAVING. This pollOnClose is always called when closing the managers.

      Attachments

        Issue Links

          Activity

            People

              lianetm Lianet Magrans
              lianetm Lianet Magrans
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: