Details
-
Bug
-
Status: Resolved
-
Resolution: Done
-
Helium
-
None
-
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.