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

KafkaProducer is not joining its IO thread properly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 0.10.2.0
    • 0.11.0.3, 1.0.1, 1.1.0
    • producer
    • None

    Description

      The KafkaProducer is not properly joining the thread it creates. The code is like this:

      try {
          this.ioThread.join(timeUnit.toMillis(timeout));
      } catch (InterruptedException t) {
          firstException.compareAndSet(null, t);
          log.error("Interrupted while joining ioThread", t);
      }
      

      If the code is interrupted while performing the join, it will end up leaving the io thread running. The correct way of handling this is a follows:

      try {
          this.ioThread.join(timeUnit.toMillis(timeout));
      } catch (InterruptedException t) {
          // propagate the interrupt
          this.ioThread.interrupt();
          try { 
               this.ioThread.join();
          } catch (InterruptedException t) {
              firstException.compareAndSet(null, t);
              log.error("Interrupted while joining ioThread", t);
          } finally {
              // make sure we maintain the interrupted status
              Thread.currentThread.interrupt();
          }
      }
      

      Attachments

        Issue Links

          Activity

            People

              huxi_2b huxihx
              bgedik Buğra Gedik
              Votes:
              2 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: