Fixes a deadlock between Agent.free() and StunClientTransaction observed in Jitsi Videobridge.
This commit is contained in:
parent
2483f4dec8
commit
0278d355f9
@ -1193,8 +1193,14 @@ public class Agent
|
||||
synchronized (mediaStreams)
|
||||
{
|
||||
mediaStreams.remove(stream.getName());
|
||||
stream.free();
|
||||
}
|
||||
/*
|
||||
* XXX The invocation of IceMediaStream#free() on stream has been moved
|
||||
* out of the synchronized block in order to reduce the chances of a
|
||||
* deadlock. There was no obvious reason why it should stay in the
|
||||
* synchronized block at the time of the modification.
|
||||
*/
|
||||
stream.free();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -460,16 +460,16 @@ class ConnectivityCheckServer
|
||||
*/
|
||||
public byte[] getRemoteKey(String username, String media)
|
||||
{
|
||||
//support both the case where username is the local fragment or the
|
||||
//entire user name.
|
||||
int colon = username.indexOf(":");
|
||||
|
||||
IceMediaStream stream = parentAgent.getStream(media);
|
||||
if(stream == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
//support both the case where username is the local fragment or the
|
||||
//entire user name.
|
||||
int colon = username.indexOf(":");
|
||||
|
||||
if (colon < 0)
|
||||
{
|
||||
//caller gave us a ufrag
|
||||
|
||||
@ -292,15 +292,13 @@ public class IceMediaStream
|
||||
{
|
||||
synchronized (components)
|
||||
{
|
||||
Iterator<Map.Entry<Integer, Component>> cmpEntries
|
||||
= components.entrySet().iterator();
|
||||
|
||||
while (cmpEntries.hasNext())
|
||||
for (Iterator<Component> i = components.values().iterator();
|
||||
i.hasNext();)
|
||||
{
|
||||
Component component = cmpEntries.next().getValue();
|
||||
Component component = i.next();
|
||||
|
||||
i.remove();
|
||||
component.free();
|
||||
cmpEntries.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ import java.util.*;
|
||||
* authority.
|
||||
*
|
||||
* @author Emil Ivov
|
||||
* @author Lyubomir Marinov
|
||||
*/
|
||||
public class CredentialsManager
|
||||
{
|
||||
@ -32,6 +33,61 @@ public class CredentialsManager
|
||||
private final List<CredentialsAuthority> authorities =
|
||||
new LinkedList<CredentialsAuthority>();
|
||||
|
||||
/**
|
||||
* The list of <tt>CredentialsAuthority</tt>s registered with this manager
|
||||
* as being able to provide credentials. If non-<tt>null</tt>, represents
|
||||
* an unmodifiable view of {@link #authorities}. The field was introduced in
|
||||
* order to reduce the scopes of the synchronization blocks of
|
||||
* <tt>CredentialsManager</tt> and to thus reduce the risks of deadlocks.
|
||||
*/
|
||||
private CredentialsAuthority[] unmodifiableAuthorities;
|
||||
|
||||
/**
|
||||
* Verifies whether <tt>username</tt> is currently known to any of the
|
||||
* {@link CredentialsAuthority}s registered with this manager and
|
||||
* and returns <tt>true</tt> if so. Returns <tt>false</tt> otherwise.
|
||||
*
|
||||
* @param username the user name whose validity we'd like to check.
|
||||
*
|
||||
* @return <tt>true</tt> if <tt>username</tt> is known to any of the
|
||||
* <tt>CredentialsAuthority</tt>s registered here and <tt>false</tt>
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean checkLocalUserName(String username)
|
||||
{
|
||||
for (CredentialsAuthority auth : getAuthorities())
|
||||
{
|
||||
if (auth.checkLocalUserName(username))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of <tt>CredentialsAuthority</tt>s registered with this
|
||||
* manager as being able to provide credentials. <b>Warning</b>: the
|
||||
* returned value is an internal state of this instance and is to be
|
||||
* considered unmodifiable.
|
||||
*
|
||||
* @return the list of <tt>CredentialsAuthority</tt>s registered with this
|
||||
* manager as being able to provide credentials. <b>Warning</b>: the
|
||||
* returned value is an internal state of this instance and is to be
|
||||
* considered unmodifiable.
|
||||
*/
|
||||
private CredentialsAuthority[] getAuthorities()
|
||||
{
|
||||
synchronized (authorities)
|
||||
{
|
||||
if (unmodifiableAuthorities == null)
|
||||
{
|
||||
unmodifiableAuthorities
|
||||
= authorities.toArray(
|
||||
new CredentialsAuthority[authorities.size()]);
|
||||
}
|
||||
return unmodifiableAuthorities;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries all currently registered {@link CredentialsAuthority}s for a
|
||||
* password corresponding to the specified local <tt>username</tt> or user
|
||||
@ -47,17 +103,12 @@ public class CredentialsManager
|
||||
*/
|
||||
public byte[] getLocalKey(String username)
|
||||
{
|
||||
synchronized(authorities)
|
||||
for (CredentialsAuthority auth : getAuthorities())
|
||||
{
|
||||
for (CredentialsAuthority auth : authorities)
|
||||
{
|
||||
byte[] passwd = auth.getLocalKey(username);
|
||||
byte[] passwd = auth.getLocalKey(username);
|
||||
|
||||
if (passwd != null)
|
||||
{
|
||||
return passwd;
|
||||
}
|
||||
}
|
||||
if (passwd != null)
|
||||
return passwd;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -78,46 +129,19 @@ public class CredentialsManager
|
||||
*/
|
||||
public byte[] getRemoteKey(String username, String media)
|
||||
{
|
||||
synchronized(authorities)
|
||||
for (CredentialsAuthority auth : getAuthorities())
|
||||
{
|
||||
for (CredentialsAuthority auth : authorities)
|
||||
{
|
||||
byte[] passwd = auth.getRemoteKey(username, media);
|
||||
byte[] passwd = auth.getRemoteKey(username, media);
|
||||
|
||||
if (passwd != null)
|
||||
{
|
||||
/** @todo: we should probably add SASLprep here.*/
|
||||
return passwd;
|
||||
}
|
||||
if (passwd != null)
|
||||
{
|
||||
/** @todo: we should probably add SASLprep here.*/
|
||||
return passwd;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies whether <tt>username</tt> is currently known to any of the
|
||||
* {@link CredentialsAuthority}s registered with this manager and
|
||||
* and returns <tt>true</tt> if so. Returns <tt>false</tt> otherwise.
|
||||
*
|
||||
* @param username the user name whose validity we'd like to check.
|
||||
*
|
||||
* @return <tt>true</tt> if <tt>username</tt> is known to any of the
|
||||
* <tt>CredentialsAuthority</tt>s registered here and <tt>false</tt>
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean checkLocalUserName(String username)
|
||||
{
|
||||
synchronized(authorities)
|
||||
{
|
||||
for (CredentialsAuthority auth : authorities)
|
||||
{
|
||||
if( auth.checkLocalUserName(username))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds <tt>authority</tt> to the list of {@link CredentialsAuthority}s
|
||||
* registered with this manager.
|
||||
@ -126,10 +150,10 @@ public class CredentialsManager
|
||||
*/
|
||||
public void registerAuthority(CredentialsAuthority authority)
|
||||
{
|
||||
synchronized(authorities)
|
||||
synchronized (authorities)
|
||||
{
|
||||
if(!authorities.contains(authority))
|
||||
authorities.add(authority);
|
||||
if (!authorities.contains(authority) && authorities.add(authority))
|
||||
unmodifiableAuthorities = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,9 +166,10 @@ public class CredentialsManager
|
||||
*/
|
||||
public void unregisterAuthority(CredentialsAuthority authority)
|
||||
{
|
||||
synchronized(authorities)
|
||||
synchronized (authorities)
|
||||
{
|
||||
authorities.remove(authority);
|
||||
if (authorities.remove(authority))
|
||||
unmodifiableAuthorities = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -385,19 +385,32 @@ class StunClientTransaction
|
||||
* @param waitForResponse indicates whether we should wait for the current
|
||||
* RTO to expire before ending the transaction or immediately terminate.
|
||||
*/
|
||||
synchronized void cancel(boolean waitForResponse)
|
||||
void cancel(boolean waitForResponse)
|
||||
{
|
||||
this.cancelled = true;
|
||||
/*
|
||||
* XXX The cancelled field is initialized to false and then the one and
|
||||
* only write access to it is here to set it to true. The rest of the
|
||||
* code just checks whether it has become true. Consequently, there
|
||||
* shouldn't be a problem if the set is outside a synchronized block.
|
||||
* However, it being outside a synchronized block will decrease the risk
|
||||
* of deadlocks.
|
||||
*/
|
||||
cancelled = true;
|
||||
|
||||
if(!waitForResponse)
|
||||
notifyAll();
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the transaction. Once this method is called the transaction is
|
||||
* considered terminated and will stop retransmissions.
|
||||
*/
|
||||
synchronized void cancel()
|
||||
void cancel()
|
||||
{
|
||||
cancel(false);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user