Skip to content

Commit 39194dd

Browse files
authored
GODRIVER-2604 Add ErrServerSelectionTimeout and WaitQueueTimeoutError to IsTimeout. (#1104)
1 parent 0175d29 commit 39194dd

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

mongo/errors.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ func IsTimeout(err error) bool {
112112
if err == driver.ErrDeadlineWouldBeExceeded {
113113
return true
114114
}
115+
if err == topology.ErrServerSelectionTimeout {
116+
return true
117+
}
118+
if _, ok := err.(topology.WaitQueueTimeoutError); ok {
119+
return true
120+
}
115121
if ce, ok := err.(CommandError); ok && ce.IsMaxTimeMSExpiredError() {
116122
return true
117123
}

mongo/integration/errors_test.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
"go.mongodb.org/mongo-driver/mongo"
2424
"go.mongodb.org/mongo-driver/mongo/integration/mtest"
2525
"go.mongodb.org/mongo-driver/mongo/options"
26+
"go.mongodb.org/mongo-driver/x/mongo/driver"
27+
"go.mongodb.org/mongo-driver/x/mongo/driver/topology"
2628
)
2729

2830
type netErr struct {
@@ -515,13 +517,25 @@ func TestErrors(t *testing.T) {
515517
err error
516518
result bool
517519
}{
518-
{"context timeout", mongo.CommandError{100, "", []string{"other"}, "blah", context.DeadlineExceeded, nil}, true},
519-
{"ServerError NetworkTimeoutError", mongo.CommandError{100, "", []string{"NetworkTimeoutError"}, "blah", nil, nil}, true},
520-
{"ServerError ExceededTimeLimitError", mongo.CommandError{100, "", []string{"ExceededTimeLimitError"}, "blah", nil, nil}, true},
521-
{"ServerError false", mongo.CommandError{100, "", []string{"other"}, "blah", nil, nil}, false},
522-
{"net error true", mongo.CommandError{100, "", []string{"other"}, "blah", netErr{true}, nil}, true},
520+
{"context timeout", mongo.CommandError{
521+
100, "", []string{"other"}, "blah", context.DeadlineExceeded, nil}, true},
522+
{"deadline would be exceeded", mongo.CommandError{
523+
100, "", []string{"other"}, "blah", driver.ErrDeadlineWouldBeExceeded, nil}, true},
524+
{"server selection timeout", mongo.CommandError{
525+
100, "", []string{"other"}, "blah", topology.ErrServerSelectionTimeout, nil}, true},
526+
{"wait queue timeout", mongo.CommandError{
527+
100, "", []string{"other"}, "blah", topology.WaitQueueTimeoutError{}, nil}, true},
528+
{"ServerError NetworkTimeoutError", mongo.CommandError{
529+
100, "", []string{"NetworkTimeoutError"}, "blah", nil, nil}, true},
530+
{"ServerError ExceededTimeLimitError", mongo.CommandError{
531+
100, "", []string{"ExceededTimeLimitError"}, "blah", nil, nil}, true},
532+
{"ServerError false", mongo.CommandError{
533+
100, "", []string{"other"}, "blah", nil, nil}, false},
534+
{"net error true", mongo.CommandError{
535+
100, "", []string{"other"}, "blah", netErr{true}, nil}, true},
523536
{"net error false", netErr{false}, false},
524-
{"wrapped error", wrappedError{mongo.CommandError{100, "", []string{"other"}, "blah", context.DeadlineExceeded, nil}}, true},
537+
{"wrapped error", wrappedError{mongo.CommandError{
538+
100, "", []string{"other"}, "blah", context.DeadlineExceeded, nil}}, true},
525539
{"other error", errors.New("foo"), false},
526540
}
527541
for _, tc := range testCases {

0 commit comments

Comments
 (0)