aboutsummaryrefslogtreecommitdiffhomepage
path: root/caddy.go
diff options
context:
space:
mode:
authorДенис Телюх <[email protected]>2022-01-05 02:14:18 +0700
committerGitHub <[email protected]>2022-01-04 12:14:18 -0700
commit2e46c2ac1d860230a80de5fd7bc85c8c9429d3f4 (patch)
tree981f0fc3fd271a62f7ff82f71718b0c34271d2d2 /caddy.go
parent249adc1c872ae46e640cfb7c330e332229d8d32a (diff)
downloadcaddy-2e46c2ac1d860230a80de5fd7bc85c8c9429d3f4.tar.gz
caddy-2e46c2ac1d860230a80de5fd7bc85c8c9429d3f4.zip
admin, reverseproxy: Stop timers if canceled to avoid goroutine leak (#4482)
Diffstat (limited to 'caddy.go')
-rw-r--r--caddy.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/caddy.go b/caddy.go
index bee4274c7..f990d362c 100644
--- a/caddy.go
+++ b/caddy.go
@@ -494,9 +494,10 @@ func finishSettingUp(ctx Context, cfg *Config) error {
if cfg.Admin.Config.LoadInterval > 0 {
go func() {
for {
+ timer := time.NewTimer(time.Duration(cfg.Admin.Config.LoadInterval))
select {
// if LoadInterval is positive, will wait for the interval and then run with new config
- case <-time.After(time.Duration(cfg.Admin.Config.LoadInterval)):
+ case <-timer.C:
loadedConfig, err := val.(ConfigLoader).LoadConfig(ctx)
if err != nil {
Log().Error("loading dynamic config failed", zap.Error(err))
@@ -504,6 +505,10 @@ func finishSettingUp(ctx Context, cfg *Config) error {
}
runLoadedConfig(loadedConfig)
case <-ctx.Done():
+ if !timer.Stop() {
+ // if the timer has been stopped then read from the channel
+ <-timer.C
+ }
Log().Info("stopping config load interval")
return
}