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

lazy val exemptSensor Could Cause Deadlock

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Blocker
    • Resolution: Fixed
    • 2.5.1
    • 3.4.0, 3.3.2
    • core
    • None

    Description

      There is a chance to cause deadlock when multiple threads access ClientRequestQuotaManager.

      In the version of Scala 2.12, the lazy val initialization is under the object lock. The deadlock could happen in the following condition:

      In thread a, when ClientRequestQuotaManager.exemptSensor is being initialized, it has acquired the object lock and enters the the actual initialization block. The initialization of 'exemptSensor' requires another lock private val lock = new ReentrantReadWriteLock() and it is waiting for this lock.

      In thread b, at the same time, ClientQuotaManager.updateQuota() is called and it has already acquired ReentrantReadWriteLock lock by calling lock.writeLock().lock(). And then it executes info(). If this is the first time accessing Logging.logger, which is also a lazy val, it need to wait for the object lock.

      Deadlock happens.

      Since the lazy val initialization is under the object lock, we should avoid using lazy val if the initialization function holds another lock to prevent holding two locks at the same time which is prone for deadlock. 

      Attachments

        Issue Links

          Activity

            People

              hshi Huilin Shi
              hshi Huilin Shi
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: