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

kafka ShutdownableThread judge thread isRuning status has some bug

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.3.1
    • None
    • core
    • None
    • Important

    Description

      1.bug

      override def run(): Unit = {
        isStarted = true
        info("Starting")
        try {
          while (isRunning)
            doWork()
        } catch {
          case e: FatalExitError =>
            shutdownInitiated.countDown()
            shutdownComplete.countDown()
            info("Stopped")
            Exit.exit(e.statusCode())
          case e: Throwable =>
            if (isRunning)
              error("Error due to", e)
        } finally {
          shutdownInitiated.countDown()
          shutdownComplete.countDown()
        }
        info("Stopped")
      }
      
      def isRunning: Boolean = {
        shutdownInitiated.getCount() != 0
      }

      1.when replicaThread has exception which is not fatalExitError, the thread will exit,and run finally logic(countdown the shutdownComplete conutdownLatch),but shutdownInitiated is not be countdown.

      2.with 1, shutdownInitiated is just not countdown, its value is 1, isRunning logic just judge thread isRuning through shutdownInitiated != 0, so through this method to judge thread status is wrong.

      3.isRunning method is used in shutdownIdleFetcherThreads, processFetchRequest, controller request send and oher else, maybe cause thread can't be remove and something can not be done

      2.bugfix

      Just like the following code,countdown shutdownInitiated in finally logic

       

      override def run(): Unit = {
        isStarted = true
        info("Starting")
        try {
          while (isRunning)
            doWork()
        } catch {
          case e: FatalExitError =>
            shutdownInitiated.countDown()
            shutdownComplete.countDown()
            info("Stopped")
            Exit.exit(e.statusCode())
          case e: Throwable =>
            if (isRunning)
              error("Error due to", e)
        } finally {
          shutdownInitiated.countDown()
          shutdownComplete.countDown()
        }
        info("Stopped")
      }
      

       

       

       

      Attachments

        Issue Links

          Activity

            People

              lushilin shilin Lu
              lushilin shilin Lu
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: