fix(netxlite/errorsx): map "use of closed network connection" (#510)
Part of https://github.com/ooni/probe/issues/1733 and diff has been extracted from https://github.com/ooni/probe-cli/pull/506.
This commit is contained in:
parent
273774bb03
commit
d7b9c8f0a8
|
@ -90,6 +90,9 @@ func classifyWithStringSuffix(err error) string {
|
|||
// that we return here is significantly more specific.
|
||||
return FailureDNSNXDOMAINError
|
||||
}
|
||||
if strings.HasSuffix(s, "use of closed network connection") {
|
||||
return FailureConnectionAlreadyClosed
|
||||
}
|
||||
return "" // not found
|
||||
}
|
||||
|
||||
|
|
|
@ -77,6 +77,13 @@ func TestClassifyGenericError(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
t.Run("for use of closed network connection", func(t *testing.T) {
|
||||
err := errors.New("read tcp 10.0.2.15:56948->93.184.216.34:443: use of closed network connection")
|
||||
if ClassifyGenericError(err) != FailureConnectionAlreadyClosed {
|
||||
t.Fatal("unexpected results")
|
||||
}
|
||||
})
|
||||
|
||||
// Now we're back in ClassifyGenericError
|
||||
|
||||
t.Run("for context.Canceled", func(t *testing.T) {
|
||||
|
@ -87,8 +94,8 @@ func TestClassifyGenericError(t *testing.T) {
|
|||
|
||||
t.Run("for unknown errors", func(t *testing.T) {
|
||||
t.Run("with an IPv4 address", func(t *testing.T) {
|
||||
input := errors.New("read tcp 10.0.2.15:56948->93.184.216.34:443: use of closed network connection")
|
||||
expected := "unknown_failure: read tcp [scrubbed]->[scrubbed]: use of closed network connection"
|
||||
input := errors.New("read tcp 10.0.2.15:56948->93.184.216.34:443: some error")
|
||||
expected := "unknown_failure: read tcp [scrubbed]->[scrubbed]: some error"
|
||||
out := ClassifyGenericError(input)
|
||||
if out != expected {
|
||||
t.Fatal(cmp.Diff(expected, out))
|
||||
|
@ -96,8 +103,8 @@ func TestClassifyGenericError(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("with an IPv6 address", func(t *testing.T) {
|
||||
input := errors.New("read tcp [::1]:56948->[::1]:443: use of closed network connection")
|
||||
expected := "unknown_failure: read tcp [scrubbed]->[scrubbed]: use of closed network connection"
|
||||
input := errors.New("read tcp [::1]:56948->[::1]:443: some error")
|
||||
expected := "unknown_failure: read tcp [scrubbed]->[scrubbed]: some error"
|
||||
out := ClassifyGenericError(input)
|
||||
if out != expected {
|
||||
t.Fatal(cmp.Diff(expected, out))
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// Generated: 2021-09-08 23:09:33.336763 +0200 CEST m=+0.192836793
|
||||
// Generated: 2021-09-27 14:20:26.411929 +0200 CEST m=+0.233208042
|
||||
|
||||
package errorsx
|
||||
|
||||
|
@ -58,6 +58,7 @@ const (
|
|||
FailureSSLUnknownAuthority = "ssl_unknown_authority"
|
||||
FailureSSLInvalidCertificate = "ssl_invalid_certificate"
|
||||
FailureJSONParseError = "json_parse_error"
|
||||
FailureConnectionAlreadyClosed = "connection_already_closed"
|
||||
)
|
||||
|
||||
// failureMap lists all failures so we can match them
|
||||
|
@ -101,6 +102,7 @@ var failuresMap = map[string]string{
|
|||
"ssl_unknown_authority": "ssl_unknown_authority",
|
||||
"ssl_invalid_certificate": "ssl_invalid_certificate",
|
||||
"json_parse_error": "json_parse_error",
|
||||
"connection_already_closed": "connection_already_closed",
|
||||
}
|
||||
|
||||
// classifySyscallError converts a syscall error to the
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// Generated: 2021-09-08 23:09:33.382965 +0200 CEST m=+0.239039834
|
||||
// Generated: 2021-09-27 14:20:26.459041 +0200 CEST m=+0.280321626
|
||||
|
||||
package errorsx
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// Generated: 2021-09-08 23:09:33.144513 +0200 CEST m=+0.000582543
|
||||
// Generated: 2021-09-27 14:20:26.179327 +0200 CEST m=+0.000601459
|
||||
|
||||
package errorsx
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// Generated: 2021-09-08 23:09:33.310337 +0200 CEST m=+0.166410043
|
||||
// Generated: 2021-09-27 14:20:26.380511 +0200 CEST m=+0.201789292
|
||||
|
||||
package errorsx
|
||||
|
||||
|
|
|
@ -101,6 +101,7 @@ var Specs = []*ErrorSpec{
|
|||
NewLibraryError("SSL_unknown_authority"),
|
||||
NewLibraryError("SSL_invalid_certificate"),
|
||||
NewLibraryError("JSON_parse_error"),
|
||||
NewLibraryError("connection_already_closed"),
|
||||
}
|
||||
|
||||
func fileCreate(filename string) *os.File {
|
||||
|
|
Loading…
Reference in New Issue
Block a user