Skip to content

Commit 51ef5ad

Browse files
committed
Update IsTransientError with additional checks.
1 parent 9fc0e47 commit 51ef5ad

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

topo/errors.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package topo
22

33
import (
4+
"context"
45
"strings"
56

67
"go.mongodb.org/mongo-driver/v2/mongo"
@@ -63,6 +64,15 @@ func isMongoCommandError(err error, name string) bool {
6364
// IsTransientError checks if the error is a transient error that can be retried.
6465
// It checks for specific MongoDB error codes that indicate transient issues.
6566
func IsTransientError(err error) bool {
67+
if mongo.IsNetworkError(err) || mongo.IsTimeout(err) || errors.Is(err, context.DeadlineExceeded) {
68+
return true
69+
}
70+
71+
le, ok := err.(mongo.LabeledError) //nolint:errorlint
72+
if ok {
73+
return le.HasErrorLabel("RetryableWriteError")
74+
}
75+
6676
transientErrorCodes := map[int]struct{}{
6777
11602: {}, // InterruptedDueToReplStateChange
6878
91: {}, // ShutdownInProgress
@@ -93,10 +103,5 @@ func IsTransientError(err error) bool {
93103
return ok
94104
}
95105

96-
le, ok := err.(mongo.LabeledError) //nolint:errorlint
97-
if ok {
98-
return le.HasErrorLabel("RetryableWriteError")
99-
}
100-
101106
return false
102107
}

0 commit comments

Comments
 (0)