mirror of
https://github.com/caddyserver/caddy.git
synced 2025-10-19 15:53:17 +00:00
admin, reverseproxy: Stop timers if canceled to avoid goroutine leak (#4482)
This commit is contained in:
parent
249adc1c87
commit
2e46c2ac1d
2 changed files with 12 additions and 2 deletions
|
@ -792,10 +792,15 @@ func (lb LoadBalancing) tryAgain(ctx caddy.Context, start time.Time, proxyErr er
|
|||
}
|
||||
|
||||
// otherwise, wait and try the next available host
|
||||
timer := time.NewTimer(time.Duration(lb.TryInterval))
|
||||
select {
|
||||
case <-time.After(time.Duration(lb.TryInterval)):
|
||||
case <-timer.C:
|
||||
return true
|
||||
case <-ctx.Done():
|
||||
if !timer.Stop() {
|
||||
// if the timer has been stopped then read from the channel
|
||||
<-timer.C
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue