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

AbstractFetcherThread.shutdown() should not block on ReadableByteChannel.read(buffer)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 0.9.0.0
    • None

    Description

      This is likely a bug from Java. This affects Kafka and here is the patch to fix it.

      Here is the description of the bug. By description of SocketChannel in Java 7 Documentation. If another thread interrupts the current thread while the read operation is in progress, the it should closes the channel and throw ClosedByInterruptException. However, we find that interrupting the thread will not unblock the channel immediately. Instead, it waits for response or socket timeout before throwing an exception.

      This will cause problem in the following scenario. Suppose one console_consumer_1 is reading from a topic, and due to quota delay or whatever reason, it block on channel.read(buffer). At this moment, another console_consumer_2 joins and triggers rebalance at console_consumer_1. But consumer_1 will block waiting on the channel.read before it can release partition ownership, causing consumer_2 to fail after a number of failed attempts to obtain partition ownership.

      In other words, AbstractFetcherThread.shutdown() is not guaranteed to shutdown due to this bug.

      The problem is confirmed with Java 1.7 and java 1.6. To check it by yourself, you can use the attached server.java and client.java – start the server before the client and see if client unblock after interruption.

      Attachments

        1. server.java
          1 kB
          Dong Lin
        2. KAFKA-2241.patch
          2 kB
          Dong Lin
        3. KAFKA-2241_2015-07-13_14:51:42.patch
          3 kB
          Dong Lin
        4. KAFKA-2241_2015-07-13_13:30:07.patch
          3 kB
          Dong Lin
        5. KAFKA-2241_2015-07-09_15:35:49.patch
          3 kB
          Dong Lin
        6. KAFKA-2241_2015-06-03_15:30:35.patch
          3 kB
          Dong Lin
        7. client.java
          2 kB
          Dong Lin

        Activity

          People

            lindong Dong Lin
            lindong Dong Lin
            Jun Rao Jun Rao
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: