Skip to content

Commit a0461a4

Browse files
author
Divjot Arora
authored
GODRIVER-1560 Ensure there is no default idle connection timeout (#369)
1 parent 8690c72 commit a0461a4

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

x/mongo/driver/topology/connection.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,11 @@ func (c *connection) close() error {
310310

311311
func (c *connection) expired() bool {
312312
now := time.Now()
313-
idleDeadline, ok := c.idleDeadline.Load().(time.Time)
314-
if ok && now.After(idleDeadline) {
315-
return true
313+
if c.idleTimeout > 0 {
314+
idleDeadline, ok := c.idleDeadline.Load().(time.Time)
315+
if ok && now.After(idleDeadline) {
316+
return true
317+
}
316318
}
317319

318320
if !c.lifetimeDeadline.IsZero() && now.After(c.lifetimeDeadline) {

x/mongo/driver/topology/connection_options.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ func newConnectionConfig(opts ...ConnectionOption) (*connectionConfig, error) {
5959
cfg := &connectionConfig{
6060
connectTimeout: 30 * time.Second,
6161
dialer: nil,
62-
idleTimeout: 10 * time.Minute,
6362
lifeTimeout: 30 * time.Minute,
6463
}
6564

x/mongo/driver/topology/connection_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"time"
1616

1717
"github.com/google/go-cmp/cmp"
18+
"go.mongodb.org/mongo-driver/internal/testutil/assert"
1819
"go.mongodb.org/mongo-driver/x/mongo/driver"
1920
"go.mongodb.org/mongo-driver/x/mongo/driver/address"
2021
"go.mongodb.org/mongo-driver/x/mongo/driver/description"
@@ -45,6 +46,13 @@ func TestConnection(t *testing.T) {
4546
t.Errorf("errors do not match. got %v; want %v", got, want)
4647
}
4748
})
49+
t.Run("no default idle timeout", func(t *testing.T) {
50+
conn, err := newConnection(context.Background(), address.Address(""))
51+
assert.Nil(t, err, "newConnection error: %v", err)
52+
wantTimeout := time.Duration(0)
53+
assert.Equal(t, wantTimeout, conn.idleTimeout, "expected idle timeout %v, got %v", wantTimeout,
54+
conn.idleTimeout)
55+
})
4856
})
4957
t.Run("connect", func(t *testing.T) {
5058
t.Run("dialer error", func(t *testing.T) {

0 commit comments

Comments
 (0)