Return more detailed error for connection reset in va (#2860)
If we hit a `syscall.ECONNRESET` error return a more useful error than `Error getting validation data`, updates the `TestDetailedError` test to cover this case. Fixes #2851.
This commit is contained in:
parent
9c7482fa94
commit
77f1364e9a
3
va/va.go
3
va/va.go
|
@ -704,6 +704,9 @@ func detailedError(err error) *probs.ProblemDetails {
|
||||||
} else if syscallErr, ok := netErr.Err.(*os.SyscallError); ok &&
|
} else if syscallErr, ok := netErr.Err.(*os.SyscallError); ok &&
|
||||||
syscallErr.Err == syscall.ECONNREFUSED {
|
syscallErr.Err == syscall.ECONNREFUSED {
|
||||||
return probs.ConnectionFailure("Connection refused")
|
return probs.ConnectionFailure("Connection refused")
|
||||||
|
} else if syscallErr, ok := netErr.Err.(*os.SyscallError); ok &&
|
||||||
|
syscallErr.Err == syscall.ECONNRESET {
|
||||||
|
return probs.ConnectionFailure("Connection reset by peer")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err, ok := err.(net.Error); ok && err.Timeout() {
|
if err, ok := err.(net.Error); ok && err.Timeout() {
|
||||||
|
|
|
@ -1526,17 +1526,37 @@ func TestPerformRemoteValidation(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDetailedError(t *testing.T) {
|
func TestDetailedError(t *testing.T) {
|
||||||
err := &net.OpError{
|
cases := []struct {
|
||||||
Op: "dial",
|
err error
|
||||||
Net: "tcp",
|
expected string
|
||||||
Err: &os.SyscallError{
|
}{
|
||||||
Syscall: "getsockopt",
|
{
|
||||||
Err: syscall.ECONNREFUSED,
|
&net.OpError{
|
||||||
|
Op: "dial",
|
||||||
|
Net: "tcp",
|
||||||
|
Err: &os.SyscallError{
|
||||||
|
Syscall: "getsockopt",
|
||||||
|
Err: syscall.ECONNREFUSED,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Connection refused",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
&net.OpError{
|
||||||
|
Op: "dial",
|
||||||
|
Net: "tcp",
|
||||||
|
Err: &os.SyscallError{
|
||||||
|
Syscall: "getsockopt",
|
||||||
|
Err: syscall.ECONNRESET,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Connection reset by peer",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
expected := "Connection refused"
|
for _, tc := range cases {
|
||||||
actual := detailedError(err).Detail
|
actual := detailedError(tc.err).Detail
|
||||||
if actual != expected {
|
if actual != tc.expected {
|
||||||
t.Errorf("Wrong detail for connection refused. Got %q, expected %q", actual, expected)
|
t.Errorf("Wrong detail for %v. Got %q, expected %q", tc.err, actual, tc.expected)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue