diff options
author | Денис Телюх <telyukh.denis@gmail.com> | 2022-01-05 02:14:18 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-04 12:14:18 -0700 |
commit | 2e46c2ac1d860230a80de5fd7bc85c8c9429d3f4 (patch) | |
tree | 981f0fc3fd271a62f7ff82f71718b0c34271d2d2 /modules | |
parent | 249adc1c872ae46e640cfb7c330e332229d8d32a (diff) |
admin, reverseproxy: Stop timers if canceled to avoid goroutine leak (#4482)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/caddyhttp/reverseproxy/reverseproxy.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/modules/caddyhttp/reverseproxy/reverseproxy.go b/modules/caddyhttp/reverseproxy/reverseproxy.go index b418953..eaa7cbf 100644 --- a/modules/caddyhttp/reverseproxy/reverseproxy.go +++ b/modules/caddyhttp/reverseproxy/reverseproxy.go @@ -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 } } |