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

Integer overflow causes incorrect node iteration in leastLoadedNode()

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.9.0.1
    • Component/s: None
    • Labels:
      None

      Description

      The leastLoadedNode() implementation iterates over all the known nodes to find a suitable candidate for sending metadata. The loop looks like this:

      for (int i = 0; i < nodes.size(); i++) {
        int idx = Utils.abs((this.nodeIndexOffset + i) % nodes.size());
        Node node = nodes.get(idx);
        ...
      }
      

      Unfortunately, this doesn't handle integer overflow correctly, which can result in some nodes in the list being passed over. For example, if the size of the node list is 5 and the random offset is Integer.MAX_VALUE, then the loop will iterate over the following indices: 2, 3, 2, 1, 0.

      In pathological cases, this can prevent the client from being able to connect to good nodes in order to refresh metadata.

        Attachments

          Activity

            People

            • Assignee:
              hachikuji Jason Gustafson
              Reporter:
              hachikuji Jason Gustafson
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: