Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deadlock observed in ice4j code #14

Closed
GoogleCodeExporter opened this issue Apr 13, 2015 · 6 comments
Closed

Deadlock observed in ice4j code #14

GoogleCodeExporter opened this issue Apr 13, 2015 · 6 comments

Comments

@GoogleCodeExporter
Copy link

We are observing deadlock using the latest version of ice4j(r300) library. We 
analysed ice4j code and could see a possibility of a deadlock occuring. Let me 
explain the scenario

After run() method of Pacemaker class is called through 
ConnectivityCheckClient.startChecks(CheckList checkList) method, Thread1 inside 
the run() method enters into the wait state due to wait(waitFor). Consider the 
case when stop method of ConnectivityCheckClient.java is called by 
Agent.terminate() method and it sets paceMaker.running as false and before it 
takes lock of paceMaker object, waitFor time elapses, Thread1 reaches the 
finally block and starts waiting for the lock of the linked list paceMakers 
object because of the statement synchronized (paceMakers)

Thread2 which is inside the stop() method of ConnectivityCheckClient.java and 
has taken the lock of the paceMakers object, now tries to take the lock of the 
pacemaker object in the statement  synchronized(paceMaker).

Now this could be a potential deadlock scenario as Thread1 is waiting to take 
the lock on paceMakers object held by Thread2 and Thread2 is waiting to take 
the lock on pacemaker object held by Thread1.

Please help us understand this scenario better. How does the ice4j code make 
sure that deadlock is avoided in this scenario, as we can see a deadlock which 
says 

"DEADLOCK DETECTED:
==================

[deadlocked thread] Timer-11:
----------------------------
Thread 'Timer-11' is waiting to acquire lock 
'org.ice4j.ice.ConnectivityCheckClient$PaceMaker@4e2753eb' that is held by 
thread 'ICE PaceMaker: null'

Stack trace:
------------
    org.ice4j.ice.ConnectivityCheckClient.stop(ConnectivityCheckClient.java:1067)
    org.ice4j.ice.Agent.terminate(Agent.java:1896)
    org.ice4j.ice.Agent.checkListStatesUpdated(Agent.java:1663)
    org.ice4j.ice.ConnectivityCheckClient$2.run(ConnectivityCheckClient.java:445)
    java.util.TimerThread.mainLoop(Timer.java:512)
    java.util.TimerThread.run(Timer.java:462)

[deadlocked thread] ICE PaceMaker: null:
---------------------------------------
Thread 'ICE PaceMaker: null' is waiting to acquire lock 
'java.util.LinkedList@77f69162' that is held by thread 'Timer-11'

Stack trace:
------------
    org.ice4j.ice.ConnectivityCheckClient$PaceMaker.run(ConnectivityCheckClient.java:1040)"




Possible Solution:

We might be able to avoid deadlock here by putting the statement 
paceMaker.running = false; in stop method of ConnectivityCheckClient.java 
inside the synchronised block, something like


                synchronized(paceMaker)
                {
                paceMaker.running = false;
                    paceMaker.notify();
                }

Please let us know your view on this

Original issue reported on code.google.com by amrinder...@gmail.com on 6 Mar 2012 at 5:09

@GoogleCodeExporter
Copy link
Author

Hi,

Your analysis is correct and we have a deadlock here. I will test your patch.

Original comment by s...@sip-communicator.org on 9 Mar 2012 at 10:36

@GoogleCodeExporter
Copy link
Author

Issue 12 has been merged into this issue.

Original comment by s...@sip-communicator.org on 9 Mar 2012 at 10:38

@GoogleCodeExporter
Copy link
Author

Issue 13 has been merged into this issue.

Original comment by s...@sip-communicator.org on 9 Mar 2012 at 11:04

@GoogleCodeExporter
Copy link
Author

We applied the patch in trunk (SVN revision 302). Thanks.

Original comment by s...@sip-communicator.org on 9 Mar 2012 at 12:04

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

Thanks for the quick turnaround on this

Original comment by amrinder...@gmail.com on 12 Mar 2012 at 4:43

@GoogleCodeExporter
Copy link
Author

Thanks for the quick turnaround on this. I came to know there is a reward 
policy in place for Google Code Hosting (code.google.com) related projects:

http://www.google.com/about/appsecurity/reward-program/

Do i wualify for this reward or any such reward policy

Original comment by amrinder...@gmail.com on 21 Aug 2013 at 5:05

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant