patorsky / ice4j

Automatically exported (2015-Jul-01) from code.google.com/p/ice4j
0 stars 0 forks source link

Deadlock observed in ice4j code | UPNPHarvester.java #15

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
We are observing deadlock using the latest version of ice4j(r302) library. We 
analysed ice4j code and could see a possibility of a deadlock occuring. Let me 
explain the scenario

When UPNPHarvester class is called, control goes to the constructor. 2 
UPNPThread instances are created and their start method is called, then the 
main thread takes lock on the rootSync object and goes into wait state.

Inside the individual thread, when each of then enters the finally block, they 
increase the finishThreads variable and call rootSync.notify() which wakes up 
the waiting main thread. The intent is that when finishThreads c=becomes 2 and 
both the UPNPThread threads have called notify only then the main thread comes 
out of the while loop and continues.

Now consider the case : main thread takes lock of rootSync object and goes into 
wait state. Out of the 2 UPNPThread threads, first one goes into finally and 
calls rootSync.notify(), main thread wakes up. Both main thread and the other 
UPNPThread thread whose start was called are now competing for lock on 
rootSynch object. If main thread gets the lock it is fine, but if the other 
UPNPThread thread gets the lock, it will call rootSync.notify() and exit. Now 
when main thread gets the lock on rootSync object, it will call wait() and go 
into the wait state indefinitely since noone will notify it.

Please let us know your view on this

Original issue reported on code.google.com by amrinder...@gmail.com on 13 Mar 2012 at 11:58