Skip to content

Commit e405458

Browse files
author
Divjot Arora
committed
GODRIVER-1560 Ensure there is no default idle connection timeout (#369)
1 parent d130800 commit e405458

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
@@ -305,9 +305,11 @@ func (c *connection) close() error {
305305

306306
func (c *connection) expired() bool {
307307
now := time.Now()
308-
idleDeadline, ok := c.idleDeadline.Load().(time.Time)
309-
if ok && now.After(idleDeadline) {
310-
return true
308+
if c.idleTimeout > 0 {
309+
idleDeadline, ok := c.idleDeadline.Load().(time.Time)
310+
if ok && now.After(idleDeadline) {
311+
return true
312+
}
311313
}
312314

313315
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
@@ -56,7 +56,6 @@ func newConnectionConfig(opts ...ConnectionOption) (*connectionConfig, error) {
5656
cfg := &connectionConfig{
5757
connectTimeout: 30 * time.Second,
5858
dialer: nil,
59-
idleTimeout: 10 * time.Minute,
6059
lifeTimeout: 30 * time.Minute,
6160
}
6261

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)