From 39194dd3110401cf977d2756d883c6954b694fc7 Mon Sep 17 00:00:00 2001 From: Benjamin Rewis <32186188+benjirewis@users.noreply.github.com> Date: Wed, 26 Oct 2022 16:14:05 -0400 Subject: [PATCH] GODRIVER-2604 Add `ErrServerSelectionTimeout` and `WaitQueueTimeoutError` to `IsTimeout`. (#1104) --- mongo/errors.go | 6 ++++++ mongo/integration/errors_test.go | 26 ++++++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/mongo/errors.go b/mongo/errors.go index d0da11426d..620022ee5d 100644 --- a/mongo/errors.go +++ b/mongo/errors.go @@ -112,6 +112,12 @@ func IsTimeout(err error) bool { if err == driver.ErrDeadlineWouldBeExceeded { return true } + if err == topology.ErrServerSelectionTimeout { + return true + } + if _, ok := err.(topology.WaitQueueTimeoutError); ok { + return true + } if ce, ok := err.(CommandError); ok && ce.IsMaxTimeMSExpiredError() { return true } diff --git a/mongo/integration/errors_test.go b/mongo/integration/errors_test.go index 28c9a16e81..b29e497908 100644 --- a/mongo/integration/errors_test.go +++ b/mongo/integration/errors_test.go @@ -23,6 +23,8 @@ import ( "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/integration/mtest" "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/x/mongo/driver" + "go.mongodb.org/mongo-driver/x/mongo/driver/topology" ) type netErr struct { @@ -515,13 +517,25 @@ func TestErrors(t *testing.T) { err error result bool }{ - {"context timeout", mongo.CommandError{100, "", []string{"other"}, "blah", context.DeadlineExceeded, nil}, true}, - {"ServerError NetworkTimeoutError", mongo.CommandError{100, "", []string{"NetworkTimeoutError"}, "blah", nil, nil}, true}, - {"ServerError ExceededTimeLimitError", mongo.CommandError{100, "", []string{"ExceededTimeLimitError"}, "blah", nil, nil}, true}, - {"ServerError false", mongo.CommandError{100, "", []string{"other"}, "blah", nil, nil}, false}, - {"net error true", mongo.CommandError{100, "", []string{"other"}, "blah", netErr{true}, nil}, true}, + {"context timeout", mongo.CommandError{ + 100, "", []string{"other"}, "blah", context.DeadlineExceeded, nil}, true}, + {"deadline would be exceeded", mongo.CommandError{ + 100, "", []string{"other"}, "blah", driver.ErrDeadlineWouldBeExceeded, nil}, true}, + {"server selection timeout", mongo.CommandError{ + 100, "", []string{"other"}, "blah", topology.ErrServerSelectionTimeout, nil}, true}, + {"wait queue timeout", mongo.CommandError{ + 100, "", []string{"other"}, "blah", topology.WaitQueueTimeoutError{}, nil}, true}, + {"ServerError NetworkTimeoutError", mongo.CommandError{ + 100, "", []string{"NetworkTimeoutError"}, "blah", nil, nil}, true}, + {"ServerError ExceededTimeLimitError", mongo.CommandError{ + 100, "", []string{"ExceededTimeLimitError"}, "blah", nil, nil}, true}, + {"ServerError false", mongo.CommandError{ + 100, "", []string{"other"}, "blah", nil, nil}, false}, + {"net error true", mongo.CommandError{ + 100, "", []string{"other"}, "blah", netErr{true}, nil}, true}, {"net error false", netErr{false}, false}, - {"wrapped error", wrappedError{mongo.CommandError{100, "", []string{"other"}, "blah", context.DeadlineExceeded, nil}}, true}, + {"wrapped error", wrappedError{mongo.CommandError{ + 100, "", []string{"other"}, "blah", context.DeadlineExceeded, nil}}, true}, {"other error", errors.New("foo"), false}, } for _, tc := range testCases {