From 377e52e387c26d40dc895519c9b4bba8ebe07f3e Mon Sep 17 00:00:00 2001 From: Aaron France Date: Sun, 29 Sep 2019 20:15:18 +0200 Subject: [PATCH] Fix Controlled agent candidate selection timeout Before if Controlled side never got any candidates it would never properly shut down. We never checked the start time against candidateSelectionTimeout Resolves pion/webrtc#854 --- selection.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/selection.go b/selection.go index 2137c17..a9fec49 100644 --- a/selection.go +++ b/selection.go @@ -190,11 +190,14 @@ func (s *controllingSelector) PingCandidate(local, remote Candidate) { } type controlledSelector struct { - agent *Agent - log logging.LeveledLogger + startTime time.Time + agent *Agent + log logging.LeveledLogger } -func (s *controlledSelector) Start() {} +func (s *controlledSelector) Start() { + s.startTime = time.Now() +} func (s *controlledSelector) ContactCandidates() { if s.agent.selectedPair != nil { @@ -203,8 +206,13 @@ func (s *controlledSelector) ContactCandidates() { s.agent.checkKeepalive() } } else { - s.log.Trace("pinging all candidates") - s.agent.pingAllCandidates() + if time.Since(s.startTime) > s.agent.candidateSelectionTimeout { + s.log.Trace("check timeout reached and no valid candidate pair found, marking connection as failed") + s.agent.updateConnectionState(ConnectionStateFailed) + } else { + s.log.Trace("pinging all candidates") + s.agent.pingAllCandidates() + } } }