Skip to content

Commit 328db7e

Browse files
GODRIVER-3173 Shore up testing
1 parent 02f048a commit 328db7e

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

x/mongo/driver/topology/cmap_prose_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,9 @@ func TestCMAPProse(t *testing.T) {
367367

368368
// There should be 0 ConnectionPendingResponseSucceeded event.
369369
require.Len(t, poolEventsByType[event.ConnectionPendingResponseSucceeded], 0)
370+
371+
// The connection should have been closed.
372+
require.Len(t, poolEventsByType[event.ConnectionClosed], 1)
370373
})
371374

372375
t.Run("connection attempts peek and succeeds", func(t *testing.T) {
@@ -465,6 +468,9 @@ func TestCMAPProse(t *testing.T) {
465468
assert.Equal(t, conn.driverConnectionID, succeeded[0].ConnectionID)
466469
assert.Equal(t, requestID, succeeded[0].RequestID)
467470
assert.Greater(t, int(succeeded[0].Duration), 0)
471+
472+
// The connection should not have been closed.
473+
require.Len(t, poolEventsByType[event.ConnectionClosed], 0)
468474
})
469475
}
470476

x/mongo/driver/topology/pool.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,14 @@ func awaitPendingResponse(ctx context.Context, pool *pool, conn *connection) err
10351035
_ = pool.checkInNoEvent(conn)
10361036
}()
10371037

1038-
if netErr, ok := err.(net.Error); ok && !netErr.Timeout() {
1038+
isCSOTTimeout := func(err error) bool {
1039+
// If the error was a timeout error, instead of closing the
1040+
// connection mark it as awaiting response so the pool can read the
1041+
// response before making it available to other operations.
1042+
nerr := net.Error(nil)
1043+
return errors.As(err, &nerr) && nerr.Timeout()
1044+
}
1045+
if !isCSOTTimeout(err) {
10391046
if err := conn.close(); err != nil {
10401047
return err
10411048
}

0 commit comments

Comments
 (0)