fix(gateway): fix error wrapping and scope in channel-only host resolution

This commit is contained in:
Sakurapainting 2026-03-27 23:48:13 +08:00
parent 58d49b5872
commit 32beb14f17

View file

@ -196,7 +196,8 @@ func resolveChannelOnlyListenHost(host string, port int) (string, error) {
if err := probeTCPBind(host, port); err == nil { if err := probeTCPBind(host, port); err == nil {
return host, nil return host, nil
} else if isLoopbackHost(host) { } else if isLoopbackHost(host) {
if fallbackErr := probeTCPBind("0.0.0.0", port); fallbackErr == nil { fallbackErr := probeTCPBind("0.0.0.0", port)
if fallbackErr == nil {
logger.WarnCF( logger.WarnCF(
"channels", "channels",
"Loopback host unavailable in channel-only mode, fallback to wildcard", "Loopback host unavailable in channel-only mode, fallback to wildcard",
@ -207,7 +208,14 @@ func resolveChannelOnlyListenHost(host string, port int) (string, error) {
) )
return "0.0.0.0", nil return "0.0.0.0", nil
} }
return "", fmt.Errorf("bind %s:%d failed: %w", host, port, err) return "", fmt.Errorf(
"bind fallback 0.0.0.0:%d failed after %s:%d failed: %w (original error: %v)",
port,
host,
port,
fallbackErr,
err,
)
} else { } else {
return "", fmt.Errorf("bind %s:%d failed: %w", host, port, err) return "", fmt.Errorf("bind %s:%d failed: %w", host, port, err)
} }