Skip to content

Commit 0f4a185

Browse files
committed
Fix timer leak
1 parent 437c966 commit 0f4a185

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

client/internal/relay/relay.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,17 @@ func (p *StunTurnProbe) ProbeAll(ctx context.Context, stuns []*stun.URI, turns [
104104

105105
p.mu.Unlock()
106106

107+
timer := time.NewTimer(1300 * time.Millisecond)
108+
defer timer.Stop()
109+
107110
select {
108111
case <-ctx.Done():
109112
log.Debugf("Context cancelled while waiting for probe results")
110113
return createErrorResults(stuns, turns)
111114
case <-probeDone:
112115
// when the probe is return fast, return the results right away
113116
return p.getCachedResults(cacheKey, stuns, turns)
114-
case <-time.After(1300 * time.Millisecond):
117+
case <-timer.C:
115118
// if the probe takes longer than 1.3s, return error results to avoid blocking
116119
return createErrorResults(stuns, turns)
117120
}

0 commit comments

Comments
 (0)