netproxy: Windows' "actively refused" is a refused connection too

Explain and sshWhy matched only "connection refused", so on Windows a
proxy or SSH server with nothing listening got no reason, only the raw
dial error. TestSSHProxySaysWhyItFailed was red on Windows at
origin/main 9bf5848c1 (win-run, xiaomi-gpu). Both now also take
WSAECONNREFUSED's "No connection could be made because the target
machine actively refused it".

Run: win-run go test ./internal/netproxy: ok. Broken by hand: refused()
matching "connection refused" only turns
TestRefusedIsExplainedOnEverySystem red (WSL).
This commit is contained in:
yetone
2026-11-19 18:04:19 +08:00
parent a4bf1a039e
commit 6ac19f4bc3
3 changed files with 31 additions and 2 deletions
+21
View File
@@ -0,0 +1,21 @@
package netproxy
import (
"strings"
"testing"
)
// Windows says a refused connection in words of its own, and a proxy or
// SSH server with nothing listening was explained on macOS and Linux
// only: TestSSHProxySaysWhyItFailed was red on Windows.
func TestRefusedIsExplainedOnEverySystem(t *testing.T) {
for _, msg := range []string{
"proxyconnect tcp: dial tcp 127.0.0.1:7890: connect: connection refused",
"proxyconnect tcp: dial tcp 127.0.0.1:7890: connectex: No connection could be made because the target machine actively refused it.",
} {
w := Explain("http://127.0.0.1:7890", msg)
if w == nil || !strings.HasPrefix(w.Why, "nothing answers at {addr}") {
t.Errorf("%q: %+v, want nothing answers", msg, w)
}
}
}
+1 -1
View File
@@ -383,7 +383,7 @@ func sshWhy(addr string, err error) error {
// keyboard-interactive at once, where the library waits for its
// questions (60), after the password was turned away
w.Why = "the SSH server at {addr} turned the login away: check the user and the password or key"
case strings.Contains(msg, "connection refused"):
case refused(msg):
w.Why = "nothing answers SSH at {addr}: check the address and port"
case strings.Contains(msg, "no such host"):
w.Why = "the SSH server's name doesn't resolve"
+9 -1
View File
@@ -63,7 +63,7 @@ func Explain(address, msg string) *Why {
w.Why = "{addr} turned the username and password away"
case strings.Contains(msg, "no acceptable authentication methods"):
w.Why = "{addr} wants a username and password"
case strings.Contains(msg, "connection refused"):
case refused(msg):
w.Why = "nothing answers at {addr}: check the address and port, and that the proxy is running"
case strings.Contains(msg, "no such host"):
w.Why = "the proxy's host name doesn't resolve"
@@ -77,6 +77,14 @@ func Explain(address, msg string) *Why {
return w
}
// refused is whether msg is a connection refused: "connection refused" on
// macOS and Linux, and Windows' "No connection could be made because the
// target machine actively refused it" (WSAECONNREFUSED), which magpie on
// Windows read as nothing it knew.
func refused(msg string) bool {
return strings.Contains(msg, "connection refused") || strings.Contains(msg, "actively refused")
}
// ExplainServer is Explain, and when the error text can't tell what
// answered (Go reads a real OpenSSH banner, "SSH-2.0-OpenSSH_9.6p1
// Ubuntu-3ubuntu13.20", as an HTTP status line with a malformed code),