From c571ca90fea92a2fcc8218c9de1cbf967e9eecbc Mon Sep 17 00:00:00 2001 From: Sean DuBois Date: Wed, 23 Oct 2019 22:16:06 -0700 Subject: [PATCH] Cancel selection timeout if Agent is closed We would always wait 10 seconds even if the ICE Agent was closed, instead return early right when the agent is closed. Closes pion/webrtc#897 --- selection.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/selection.go b/selection.go index a9fec49..a8e718b 100644 --- a/selection.go +++ b/selection.go @@ -27,7 +27,12 @@ type controllingSelector struct { func (s *controllingSelector) Start() { s.startTime = time.Now() go func() { - time.Sleep(s.agent.candidateSelectionTimeout) + select { + case <-s.agent.done: + return + case <-time.After(s.agent.candidateSelectionTimeout): + } + err := s.agent.run(func(a *Agent) { if s.nominatedPair == nil { p := s.agent.getBestValidCandidatePair()