Fix a race stopping a connectivity check client. (#237)

* Fix a race stopping a connectivity check client.

(This could result in the agent, and everything it references, staying reachable and so being leaked.)
This commit is contained in:
Jonathan Lennox 2021-08-24 17:40:35 -04:00 committed by GitHub
parent 076281c76b
commit adca67b17f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,6 +21,7 @@ import java.net.*;
import java.time.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import org.ice4j.*;
import org.ice4j.attribute.*;
@ -67,6 +68,12 @@ class ConnectivityCheckClient
private final Queue<PaceMaker> paceMakers
= new ConcurrentLinkedQueue<>();
/**
* Whether this {@link ConnectivityCheckClient} has been stopped.
* Synchronized by {@link #paceMakers}.
*/
private boolean stopped = false;
/**
* Timer that is used to let some seconds before a CheckList is considered
* as FAILED.
@ -160,10 +167,17 @@ class ConnectivityCheckClient
*/
public void startChecks(CheckList checkList)
{
synchronized (paceMakers)
{
if (stopped)
{
return;
}
PaceMaker paceMaker = new PaceMaker(checkList);
paceMakers.add(paceMaker);
paceMaker.schedule();
}
}
/**
* Creates a STUN Binding {@link Indication} to a candidate pair. It is used
@ -969,6 +983,9 @@ class ConnectivityCheckClient
*/
public void stop()
{
synchronized (paceMakers)
{
stopped = true;
while (true)
{
final PaceMaker paceMaker = paceMakers.poll();
@ -980,3 +997,4 @@ class ConnectivityCheckClient
}
}
}
}