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:
Simone Basso 2021-09-27 14:40:25 +02:00 committed by GitHub
parent 273774bb03
commit d7b9c8f0a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 8 deletions

View File

@ -90,6 +90,9 @@ func classifyWithStringSuffix(err error) string {
// that we return here is significantly more specific. // that we return here is significantly more specific.
return FailureDNSNXDOMAINError return FailureDNSNXDOMAINError
} }
if strings.HasSuffix(s, "use of closed network connection") {
return FailureConnectionAlreadyClosed
}
return "" // not found return "" // not found
} }

View File

@ -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 // Now we're back in ClassifyGenericError
t.Run("for context.Canceled", func(t *testing.T) { 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("for unknown errors", func(t *testing.T) {
t.Run("with an IPv4 address", 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") input := errors.New("read tcp 10.0.2.15:56948->93.184.216.34:443: some error")
expected := "unknown_failure: read tcp [scrubbed]->[scrubbed]: use of closed network connection" expected := "unknown_failure: read tcp [scrubbed]->[scrubbed]: some error"
out := ClassifyGenericError(input) out := ClassifyGenericError(input)
if out != expected { if out != expected {
t.Fatal(cmp.Diff(expected, out)) 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) { t.Run("with an IPv6 address", func(t *testing.T) {
input := errors.New("read tcp [::1]:56948->[::1]:443: use of closed network connection") input := errors.New("read tcp [::1]:56948->[::1]:443: some error")
expected := "unknown_failure: read tcp [scrubbed]->[scrubbed]: use of closed network connection" expected := "unknown_failure: read tcp [scrubbed]->[scrubbed]: some error"
out := ClassifyGenericError(input) out := ClassifyGenericError(input)
if out != expected { if out != expected {
t.Fatal(cmp.Diff(expected, out)) t.Fatal(cmp.Diff(expected, out))

View File

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT. // 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 package errorsx
@ -58,6 +58,7 @@ const (
FailureSSLUnknownAuthority = "ssl_unknown_authority" FailureSSLUnknownAuthority = "ssl_unknown_authority"
FailureSSLInvalidCertificate = "ssl_invalid_certificate" FailureSSLInvalidCertificate = "ssl_invalid_certificate"
FailureJSONParseError = "json_parse_error" FailureJSONParseError = "json_parse_error"
FailureConnectionAlreadyClosed = "connection_already_closed"
) )
// failureMap lists all failures so we can match them // 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_unknown_authority": "ssl_unknown_authority",
"ssl_invalid_certificate": "ssl_invalid_certificate", "ssl_invalid_certificate": "ssl_invalid_certificate",
"json_parse_error": "json_parse_error", "json_parse_error": "json_parse_error",
"connection_already_closed": "connection_already_closed",
} }
// classifySyscallError converts a syscall error to the // classifySyscallError converts a syscall error to the

View File

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT. // 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 package errorsx

View File

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT. // 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 package errorsx

View File

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT. // 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 package errorsx

View File

@ -101,6 +101,7 @@ var Specs = []*ErrorSpec{
NewLibraryError("SSL_unknown_authority"), NewLibraryError("SSL_unknown_authority"),
NewLibraryError("SSL_invalid_certificate"), NewLibraryError("SSL_invalid_certificate"),
NewLibraryError("JSON_parse_error"), NewLibraryError("JSON_parse_error"),
NewLibraryError("connection_already_closed"),
} }
func fileCreate(filename string) *os.File { func fileCreate(filename string) *os.File {