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.
This commit is contained in:
Cuong Manh Le
2026-08-12 14:46:48 +07:00
parent 24fc9085fa
commit 0c8281c879
2 changed files with 9 additions and 4 deletions
+3 -3
View File
@@ -289,7 +289,7 @@ func run(appCallback *AppCallback, stopCh chan struct{}) {
} }
p.mu.Unlock() p.mu.Unlock()
processLogAndCacheFlags() processLogAndCacheFlags(v, &cfg)
// Log config do not have thing to validate, so it's safe to init log here, // 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. // so it's able to log information in processCDFlags.
@@ -340,7 +340,7 @@ func run(appCallback *AppCallback, stopCh chan struct{}) {
updated := updateListenerConfig(&cfg, notifyExitToLogServer) updated := updateListenerConfig(&cfg, notifyExitToLogServer)
if cdUID != "" { if cdUID != "" {
processLogAndCacheFlags() processLogAndCacheFlags(v, &cfg)
} }
// Persist intercept_mode to config when provided via CLI flag on full install. // Persist intercept_mode to config when provided via CLI flag on full install.
@@ -851,7 +851,7 @@ func processListenFlag() {
} }
// processLogAndCacheFlags processes log and cache related flags // processLogAndCacheFlags processes log and cache related flags
func processLogAndCacheFlags() { func processLogAndCacheFlags(v *viper.Viper, cfg *ctrld.Config) {
mainLog.Load().Debug().Msg("Processing log and cache flags") mainLog.Load().Debug().Msg("Processing log and cache flags")
if logPath != "" { if logPath != "" {
+6 -1
View File
@@ -322,7 +322,8 @@ func (p *prog) runWait() {
continue continue
} }
if cdUID != "" { if cdUID != "" {
if rc, err := processCDFlags(newCfg); err != nil { rc, err := processCDFlags(newCfg)
if err != nil {
p.Error().Err(err).Msg("Could not fetch controld config") p.Error().Err(err).Msg("Could not fetch controld config")
waitOldRunDone() waitOldRunDone()
continue continue
@@ -334,6 +335,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() waitOldRunDone()
p.mu.Lock() p.mu.Lock()