Skip to content

Commit a8291f3

Browse files
committed
fix mongo transient tls error
1 parent a26a0bc commit a8291f3

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

flow/alerting/classifier.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const (
4545
MongoShutdownInProgress = "(ShutdownInProgress) The server is in quiesce mode and will shut down"
4646
MongoInterruptedDueToReplStateChange = "(InterruptedDueToReplStateChange) operation was interrupted"
4747
MongoIncompleteReadOfMessageHeader = "incomplete read of message header"
48+
MongoTLSInvalidServerCertSignature = "tls: invalid signature by the server certificate"
4849

4950
// mysqlGeometryLinearRingNotClosedError is the specific WKB parse failure raised by the
5051
// go-geos library when a LinearRing's points do not close. Used to give a more specific code
@@ -817,6 +818,12 @@ func GetErrorClass(ctx context.Context, err error) (ErrorClass, ErrorInfo) {
817818
return ErrorNotifyConnectivity, mongoErrorInfo
818819
}
819820

821+
// TLS handshake failures during connection checkout is typically retryable. We've observed
822+
// Atlas briefly serving a mismatched cert/key pair during rolling cert rotation that auto-recovers
823+
if strings.Contains(err.Error(), MongoTLSInvalidServerCertSignature) {
824+
return ErrorRetryRecoverable, mongoErrorInfo
825+
}
826+
820827
// https://www.mongodb.com/docs/manual/reference/error-codes/
821828
switch mongoCmdErr.Code {
822829
case 6: // HostUnreachable

flow/alerting/classifier_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/stretchr/testify/require"
2626
"go.mongodb.org/mongo-driver/v2/mongo"
2727
"go.mongodb.org/mongo-driver/v2/x/mongo/driver"
28+
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology"
2829
"go.temporal.io/sdk/temporal"
2930
"google.golang.org/api/googleapi"
3031

@@ -846,6 +847,29 @@ func TestMongoCursorErrors(t *testing.T) {
846847
}, errInfo)
847848
}
848849

850+
func TestMongoTLSInvalidServerCertSignatureShouldBeRecoverable(t *testing.T) {
851+
de := driver.Error{
852+
Labels: []string{driver.NetworkError},
853+
Wrapped: topology.ConnectionError{
854+
Wrapped: errors.New(
855+
"failed to configure TLS for pl-1-us-east-1.xxxx.mongodb.net:1234: " +
856+
"tls: invalid signature by the server certificate: crypto/rsa: verification error"),
857+
},
858+
}
859+
err := mongo.CommandError{
860+
Code: de.Code,
861+
Message: de.Message,
862+
Labels: de.Labels,
863+
Wrapped: de,
864+
}
865+
errorClass, errInfo := GetErrorClass(t.Context(), fmt.Errorf("failed to create change stream: %w", err))
866+
assert.Equal(t, ErrorRetryRecoverable, errorClass)
867+
assert.Equal(t, ErrorInfo{
868+
Source: ErrorSourceMongoDB,
869+
Code: "0",
870+
}, errInfo)
871+
}
872+
849873
func TestAuroraMySQLZeroDowntimePatchErrorShouldBeRecoverable(t *testing.T) {
850874
// Simulate Aurora MySQL Zero Downtime Patch error
851875
mysqlErr := &mysql.MyError{

0 commit comments

Comments
 (0)