Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 13, 21:45 UTC
core: Config load interval only reloads if changed (#4603)
Noorain Panjwani committed
Mar 2, 2022 at 00:02 UTC
7ea5b2a818ff56f650c537be83c4230166f90a14
1 file changed
+15
-2
caddy.go
+15
-2
@@ -481,11 +481,23 @@ func finishSettingUp(ctx Context, cfg *Config) error {
481
return fmt.Errorf("loading config loader module: %s", err)
482
}
483
runLoadedConfig := func(config []byte) {
484
- Log().Info("applying dynamically-loaded config", zap.String("loader_module", val.(Module).CaddyModule().ID.Name()), zap.Int("pull_interval", int(cfg.Admin.Config.LoadInterval)))
484
currentCfgMu.Lock()
485
+ defer currentCfgMu.Unlock()
486
+
487
+ // Skip if there is no change in the config
488
+ if bytes.Equal(rawCfgJSON, config) {
489
+ return
490
+ }
491
+
492
+ Log().Info("applying dynamically-loaded config", zap.String("loader_module", val.(Module).CaddyModule().ID.Name()), zap.Int("pull_interval", int(cfg.Admin.Config.LoadInterval)))
493
err := unsyncedDecodeAndRun(config, false)
487
- currentCfgMu.Unlock()
494
if err == nil {
495
+ // success, so update our stored copy of the encoded
496
+ // config to keep it consistent with what caddy is now
497
+ // running (storing an encoded copy is not strictly
498
+ // necessary, but avoids an extra json.Marshal for
499
+ // each config change)
500
+ rawCfgJSON = config
501
Log().Info("dynamically-loaded config applied successfully")
502
} else {
503
Log().Error("running dynamically-loaded config failed", zap.Error(err))
@@ -503,6 +515,7 @@ func finishSettingUp(ctx Context, cfg *Config) error {
515
Log().Error("loading dynamic config failed", zap.Error(err))
516
return
517
}
518
+
519
runLoadedConfig(loadedConfig)
520
case <-ctx.Done():
521
if !timer.Stop() {