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.
This commit is contained in:
Cuong Manh Le
2025-07-22 18:13:13 +07:00
committed by Cuong Manh Le
parent ddbb0f0db4
commit ec85b1621d

View File

@@ -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 {