Uploaded image for project: 'controller'
  1. controller
  2. CONTROLLER-636

Deadlock scenario with DataChangeListeners

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • Resolution: Done
    • Helium
    • None
    • mdsal
    • None
    • Operating System: All
      Platform: All

    • 1386
    • High

    Description

      There is a deadlock scenario with DataChangeListeners if they commit a write transaction and call get() on the Future to synchronously wait for the response, as in the following code.

      public void onDataChanged( ... )

      { ... WriteTransaction tx = dataBroker.newWriteOnlyTransaction( ... ); tx.submit().get(); // blocking call }

      If the code handled the Future async via a FutureCallback then there wouldn't be an issue.

      The reason is that a shared single-threaded executor is used to perform commits and notify DataChangeListeners.

      The single-threaded nature of commits and notifications will be looked at further at some point but, in the mean time, we can at least detect this situation and throw an exception to avoid deadlock.

      We can use a ThreadLocal variable that is set in the commit/notification thread. We can subclass the returned Future and, When get() is called, check if the ThreadLocal is set and, if so, set an exception in the Future.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            tpantelis Tom Pantelis
            tpantelis Tom Pantelis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: