From f9ee7aedbaf9b613277f17665e748693389f901d Mon Sep 17 00:00:00 2001 From: boris Date: Mon, 9 Mar 2015 18:24:42 +0000 Subject: [PATCH] Synchronizes access to an Agent's termination thread because of an observed race condition leading to calling start() twice. 14:29:26.756 INFO: [28] org.ice4j.ice.ConnectivityCheckClient.processSuccessResponse() Nomination confirmed for pair: 192.168.1.116:7777/udp/host -> 192.168.1.116:62365/udp/prflx (stream.RTP) 14:29:26.757 INFO: [28] org.ice4j.ice.CheckList.handleNominationConfirmed() Selected pair for stream stream.RTP: 192.168.1.116:7777/udp/host -> 192.168.1.116:62365/udp/prflx (stream.RTP) 14:29:26.758 INFO: [29] org.ice4j.ice.Agent.checkListStatesUpdated() CheckList of stream stream is COMPLETED 14:29:26.758 INFO: [28] org.ice4j.ice.Agent.checkListStatesUpdated() CheckList of stream stream is COMPLETED 14:29:26.758 INFO: [29] org.ice4j.ice.Agent.checkListStatesUpdated() ICE state is COMPLETED 14:29:26.758 INFO: [28] org.ice4j.ice.Agent.checkListStatesUpdated() ICE state is COMPLETED 14:29:26.758 INFO: [29] org.jitsi.videobridge.IceUdpTransportManager.info() ICE processing state of IceUdpTransportManager #2dcab970 (for channels ca079f8cc6778b96 38480814176d5f95 727e3ef175b4a77c) of con ference bd46bc5c213945f7 changed from Running to Completed. 14:29:26.759 INFO: [28] org.jitsi.videobridge.IceUdpTransportManager.info() ICE processing state of IceUdpTransportManager #2dcab970 (for channels ca079f8cc6778b96 38480814176d5f95 727e3ef175b4a77c) of con ference bd46bc5c213945f7 changed from Completed to Completed. 14:29:26.766 INFO: [29] org.ice4j.ice.Agent.logCandTypes() Harvester used for selected pair for stream.RTP: host 14:29:26.769 WARNING: [28] org.ice4j.stack.NetAccessManager.handleFatalError() A message processor has unexpectedly stopped. AP:org.ice4j.stack.MessageProcessor@de4a162 java.lang.IllegalThreadStateException at java.lang.Thread.start(Thread.java:705) at org.ice4j.ice.Agent.scheduleTermination(Agent.java:1930) at org.ice4j.ice.Agent.checkListStatesUpdated(Agent.java:1726) at org.ice4j.ice.ConnectivityCheckClient.updateCheckListAndTimerStates(ConnectivityCheckClient.java:437) at org.ice4j.ice.ConnectivityCheckClient.processResponse(ConnectivityCheckClient.java:360) at org.ice4j.stack.StunClientTransaction.handleResponse(StunClientTransaction.java:492) at org.ice4j.stack.StunStack.handleMessageEvent(StunStack.java:1028) at org.ice4j.stack.MessageProcessor.run(MessageProcessor.java:159) at java.lang.Thread.run(Thread.java:745) --- src/org/ice4j/ice/Agent.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/org/ice4j/ice/Agent.java b/src/org/ice4j/ice/Agent.java index 32bcfc3..bcc039c 100644 --- a/src/org/ice4j/ice/Agent.java +++ b/src/org/ice4j/ice/Agent.java @@ -225,6 +225,11 @@ public class Agent */ private TerminationThread terminationThread; + /** + * The object used to synchronize access to {@link #terminationThread}. + */ + private final Object terminationThreadSyncRoot = new Object(); + /** * The thread that we use for STUN keep-alive. */ @@ -1929,10 +1934,13 @@ public class Agent */ private void scheduleTermination() { - if (terminationThread == null) + synchronized (terminationThreadSyncRoot) { - terminationThread = new TerminationThread(); - terminationThread.start(); + if (terminationThread == null) + { + terminationThread = new TerminationThread(); + terminationThread.start(); + } } } @@ -2012,7 +2020,10 @@ public class Agent logger.info("ICE state is TERMINATED"); terminate(IceProcessingState.TERMINATED); - terminationThread = null; + synchronized (terminationThreadSyncRoot) + { + terminationThread = null; + } } }