From 80e652b8d90f14a3b98b6032f9cc80fbbedb92c2 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Tue, 4 Nov 2025 20:03:04 +0700 Subject: [PATCH] fix: ensure log and cache flags are processed during reload During reload operations, log and cache flags were not being processed, which prevented runtime internal logs from working correctly. To fix this, processLogAndCacheFlags was refactored to accept explicit viper and config parameters instead of relying on global state, enabling it to be called during reload with the new configuration. This ensures that log and cache settings are properly applied when the service reloads its configuration. --- cmd/cli/cli.go | 7 ++++--- cmd/cli/prog.go | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/cli/cli.go b/cmd/cli/cli.go index 1984f70..7d70b78 100644 --- a/cmd/cli/cli.go +++ b/cmd/cli/cli.go @@ -282,7 +282,7 @@ func run(appCallback *AppCallback, stopCh chan struct{}) { } p.mu.Unlock() - processLogAndCacheFlags() + processLogAndCacheFlags(v, &cfg) // Log config do not have thing to validate, so it's safe to init log here, // so it's able to log information in processCDFlags. @@ -342,7 +342,7 @@ func run(appCallback *AppCallback, stopCh chan struct{}) { updated := updateListenerConfig(&cfg, notifyExitToLogServer) if cdUID != "" { - processLogAndCacheFlags() + processLogAndCacheFlags(v, &cfg) } if updated { @@ -780,7 +780,8 @@ func processListenFlag() { }) } -func processLogAndCacheFlags() { +// processLogAndCacheFlags processes log and cache related flags +func processLogAndCacheFlags(v *viper.Viper, cfg *ctrld.Config) { if logPath != "" { cfg.Service.LogPath = logPath } diff --git a/cmd/cli/prog.go b/cmd/cli/prog.go index 76f7c36..cf8c680 100644 --- a/cmd/cli/prog.go +++ b/cmd/cli/prog.go @@ -213,7 +213,8 @@ func (p *prog) runWait() { continue } if cdUID != "" { - if rc, err := processCDFlags(newCfg); err != nil { + rc, err := processCDFlags(newCfg) + if err != nil { logger.Err(err).Msg("could not fetch ControlD config") waitOldRunDone() continue @@ -225,6 +226,10 @@ func (p *prog) runWait() { } } + // Though the log configuration could not be changed during reloading, we still need to + // process the current flags here, so runtime internal logs can be used correctly. + processLogAndCacheFlags(v, newCfg) + waitOldRunDone() p.mu.Lock()