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 db9e335d60
commit b80a7b6a82

View file

@ -192,14 +192,26 @@ 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)
logger.WarnCF("channels", "Loopback host unavailable in channel-only mode, fallback to wildcard", map[string]any{ if fallbackErr == nil {
logger.WarnCF(
"channels",
"Loopback host unavailable in channel-only mode, fallback to wildcard",
map[string]any{
"host": host, "host": host,
"port": port, "port": port,
}) },
)
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)
} }