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:
parent
076281c76b
commit
adca67b17f
@ -21,6 +21,7 @@ import java.net.*;
|
|||||||
import java.time.*;
|
import java.time.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
import java.util.concurrent.atomic.*;
|
||||||
|
|
||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
import org.ice4j.attribute.*;
|
import org.ice4j.attribute.*;
|
||||||
@ -67,6 +68,12 @@ class ConnectivityCheckClient
|
|||||||
private final Queue<PaceMaker> paceMakers
|
private final Queue<PaceMaker> paceMakers
|
||||||
= new ConcurrentLinkedQueue<>();
|
= 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
|
* Timer that is used to let some seconds before a CheckList is considered
|
||||||
* as FAILED.
|
* as FAILED.
|
||||||
@ -160,9 +167,16 @@ class ConnectivityCheckClient
|
|||||||
*/
|
*/
|
||||||
public void startChecks(CheckList checkList)
|
public void startChecks(CheckList checkList)
|
||||||
{
|
{
|
||||||
PaceMaker paceMaker = new PaceMaker(checkList);
|
synchronized (paceMakers)
|
||||||
paceMakers.add(paceMaker);
|
{
|
||||||
paceMaker.schedule();
|
if (stopped)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PaceMaker paceMaker = new PaceMaker(checkList);
|
||||||
|
paceMakers.add(paceMaker);
|
||||||
|
paceMaker.schedule();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -969,14 +983,18 @@ class ConnectivityCheckClient
|
|||||||
*/
|
*/
|
||||||
public void stop()
|
public void stop()
|
||||||
{
|
{
|
||||||
while (true)
|
synchronized (paceMakers)
|
||||||
{
|
{
|
||||||
final PaceMaker paceMaker = paceMakers.poll();
|
stopped = true;
|
||||||
if (paceMaker == null)
|
while (true)
|
||||||
{
|
{
|
||||||
break;
|
final PaceMaker paceMaker = paceMakers.poll();
|
||||||
|
if (paceMaker == null)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
paceMaker.cancel();
|
||||||
}
|
}
|
||||||
paceMaker.cancel();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user