From ec85b1621def4753e45e8f0a56f737baa3e3f023 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Tue, 22 Jul 2025 18:13:13 +0700 Subject: [PATCH] fix: improve listener configuration and error logging - Add condition to skip port 53 attempts when using zero IP address - Improve error logging by using structured error field instead of string formatting - Remove redundant error information from log message format The changes prevent unnecessary port 53 binding attempts when using zero IP addresses and improve log readability by using zap's structured error fields. --- cmd/cli/cli.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/cli/cli.go b/cmd/cli/cli.go index 0b78909..dc4b14b 100644 --- a/cmd/cli/cli.go +++ b/cmd/cli/cli.go @@ -1247,6 +1247,9 @@ func tryUpdateListenerConfig(cfg *ctrld.Config, notifyFunc func(), fatal bool) ( // config, so we can always listen on localhost port 53, but no traffic could be routed there. tryLocalhost := !isLoopback(listener.IP) tryAllPort53 := true + if isZeroIP && listener.Port == 53 { + tryAllPort53 = false + } attempts := 0 maxAttempts := 10 @@ -1261,7 +1264,7 @@ func tryUpdateListenerConfig(cfg *ctrld.Config, notifyFunc func(), fatal bool) ( break } - logMsg(il.Info(), n, "error listening on address: %s, error: %v", addr, err) + logMsg(il.Info().Err(err), n, "error listening on address: %s", addr) if !check.IP && !check.Port { if fatal {