Skip to content

Commit 486ba91

Browse files
committed
GODRIVER-2577 Polish after review.
1 parent 28c8df9 commit 486ba91

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

x/mongo/driver/topology/server.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -554,23 +554,30 @@ func (s *Server) update() {
554554
defer s.processErrorLock.Unlock()
555555

556556
s.updateDescription(desc)
557-
if lastError := desc.LastError; lastError != nil {
558-
// Retry after the first timeout in case of a FAAS pause as described in GODRIVER-2577.
559-
if err := unwrapConnectionError(lastError); err != nil {
560-
err, ok := err.(net.Error)
561-
if ok && err.Timeout() && timeoutCnt < 1 {
562-
timeoutCnt++
563-
// Continue to next loop.
564-
return true
565-
}
557+
// Retry after the first timeout before clearing the pool in case of a FAAS pause as
558+
// described in GODRIVER-2577.
559+
if err := unwrapConnectionError(desc.LastError); err != nil && timeoutCnt < 1 {
560+
if err == context.Canceled || err == context.DeadlineExceeded {
561+
timeoutCnt++
562+
// We want to immediately retry on timeout error. Continue to next loop.
563+
return true
566564
}
565+
if err, ok := err.(net.Error); ok && err.Timeout() {
566+
timeoutCnt++
567+
// We want to immediately retry on timeout error. Continue to next loop.
568+
return true
569+
}
570+
}
571+
if err := desc.LastError; err != nil {
567572
// Clear the pool once the description has been updated to Unknown. Pass in a nil service ID to clear
568573
// because the monitoring routine only runs for non-load balanced deployments in which servers don't return
569574
// IDs.
570575
s.pool.clear(err, nil)
571576
}
577+
// We're either not handling a timeout error, or we just handled the 2nd consecutive
578+
// timeout error. In either case, reset the timeout count to 0 and return false to
579+
// continue the normal check process.
572580
timeoutCnt = 0
573-
// Run forward.
574581
return false
575582
}(); isShortcut {
576583
continue

x/mongo/driver/topology/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func TestServerHeartbeatTimeout(t *testing.T) {
181181
}
182182
}),
183183
WithHeartbeatInterval(func(time.Duration) time.Duration {
184-
return 2 * time.Second
184+
return 200 * time.Millisecond
185185
}),
186186
)
187187
require.NoError(t, server.Connect(nil))

0 commit comments

Comments
 (0)