-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: classify incomplete requests as retriable
feat(proxy_round_tripper): Use atomics instead of mutexes for traces
- Loading branch information
1 parent
8ca9d2f
commit a7dbf84
Showing
12 changed files
with
345 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,88 @@ | ||
package fails | ||
|
||
import ( | ||
"context" | ||
"crypto/tls" | ||
"crypto/x509" | ||
"errors" | ||
"net" | ||
|
||
"context" | ||
"strings" | ||
) | ||
|
||
var IdempotentRequestEOFError = errors.New("EOF (via idempotent request)") | ||
|
||
var IncompleteRequestError = errors.New("incomplete request") | ||
|
||
var AttemptedTLSWithNonTLSBackend = ClassifierFunc(func(err error) bool { | ||
switch err.(type) { | ||
case tls.RecordHeaderError, *tls.RecordHeaderError: | ||
return true | ||
default: | ||
return false | ||
} | ||
return errors.As(err, &tls.RecordHeaderError{}) | ||
}) | ||
|
||
var Dial = ClassifierFunc(func(err error) bool { | ||
ne, ok := err.(*net.OpError) | ||
return ok && ne.Op == "dial" | ||
var opErr *net.OpError | ||
if errors.As(err, &opErr) { | ||
return opErr.Op == "dial" | ||
} | ||
return false | ||
}) | ||
|
||
var ContextCancelled = ClassifierFunc(func(err error) bool { | ||
return err == context.Canceled | ||
return errors.Is(err, context.Canceled) | ||
}) | ||
|
||
var ConnectionResetOnRead = ClassifierFunc(func(err error) bool { | ||
ne, ok := err.(*net.OpError) | ||
return ok && ne.Op == "read" && ne.Err.Error() == "read: connection reset by peer" | ||
var opErr *net.OpError | ||
if errors.As(err, &opErr) { | ||
return opErr.Err.Error() == "read: connection reset by peer" | ||
} | ||
return false | ||
}) | ||
|
||
var RemoteFailedCertCheck = ClassifierFunc(func(err error) bool { | ||
return err != nil && (err.Error() == "readLoopPeekFailLocked: remote error: tls: bad certificate" || err.Error() == "remote error: tls: bad certificate") | ||
var opErr *net.OpError | ||
if errors.As(err, &opErr) { | ||
return opErr.Op == "remote error" && opErr.Err.Error() == "tls: bad certificate" | ||
} | ||
return false | ||
}) | ||
|
||
var RemoteHandshakeTimeout = ClassifierFunc(func(err error) bool { | ||
return err != nil && err.Error() == "net/http: TLS handshake timeout" | ||
return err != nil && strings.Contains(err.Error(), "net/http: TLS handshake timeout") | ||
}) | ||
|
||
var ExpiredOrNotYetValidCertFailure = ClassifierFunc(func(err error) bool { | ||
switch x509err := err.(type) { | ||
case x509.CertificateInvalidError: | ||
return x509err.Reason == x509.Expired | ||
case *x509.CertificateInvalidError: | ||
return x509err.Reason == x509.Expired | ||
default: | ||
return false | ||
var certErr x509.CertificateInvalidError | ||
if errors.As(err, &certErr) { | ||
return certErr.Reason == x509.Expired | ||
} | ||
return false | ||
}) | ||
|
||
var RemoteHandshakeFailure = ClassifierFunc(func(err error) bool { | ||
return err != nil && err.Error() == "remote error: tls: handshake failure" | ||
var opErr *net.OpError | ||
if errors.As(err, &opErr) { | ||
return opErr != nil && opErr.Error() == "remote error: tls: handshake failure" | ||
} | ||
return false | ||
}) | ||
|
||
var HostnameMismatch = ClassifierFunc(func(err error) bool { | ||
switch err.(type) { | ||
case x509.HostnameError, *x509.HostnameError: | ||
return true | ||
default: | ||
return false | ||
} | ||
return errors.As(err, &x509.HostnameError{}) | ||
}) | ||
|
||
var UntrustedCert = ClassifierFunc(func(err error) bool { | ||
switch err.(type) { | ||
case x509.UnknownAuthorityError, *x509.UnknownAuthorityError: | ||
var tlsCertError *tls.CertificateVerificationError | ||
switch { | ||
case errors.As(err, &x509.UnknownAuthorityError{}), errors.As(err, &tlsCertError): | ||
return true | ||
default: | ||
return false | ||
} | ||
}) | ||
|
||
var IdempotentRequestEOF = ClassifierFunc(func(err error) bool { | ||
return err == IdempotentRequestEOFError | ||
return errors.Is(err, IdempotentRequestEOFError) | ||
}) | ||
|
||
var IncompleteRequest = ClassifierFunc(func(err error) bool { | ||
return errors.Is(err, IncompleteRequestError) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.