Skip to content

Commit eb00544

Browse files
author
Divjot Arora
committed
GODRIVER-1742 Remove connection life timeout (#499)
1 parent 70d5060 commit eb00544

File tree

3 files changed

+5
-23
lines changed

3 files changed

+5
-23
lines changed

x/mongo/driver/topology/connection.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ type connection struct {
3636
addr address.Address
3737
idleTimeout time.Duration
3838
idleDeadline atomic.Value // Stores a time.Time
39-
lifetimeDeadline time.Time
4039
readTimeout time.Duration
4140
writeTimeout time.Duration
4241
desc description.Server
@@ -68,18 +67,12 @@ func newConnection(addr address.Address, opts ...ConnectionOption) (*connection,
6867
return nil, err
6968
}
7069

71-
var lifetimeDeadline time.Time
72-
if cfg.lifeTimeout > 0 {
73-
lifetimeDeadline = time.Now().Add(cfg.lifeTimeout)
74-
}
75-
7670
id := fmt.Sprintf("%s[-%d]", addr, nextConnectionID())
7771

7872
c := &connection{
7973
id: id,
8074
addr: addr,
8175
idleTimeout: cfg.idleTimeout,
82-
lifetimeDeadline: lifetimeDeadline,
8376
readTimeout: cfg.readTimeout,
8477
writeTimeout: cfg.writeTimeout,
8578
connectDone: make(chan struct{}),
@@ -383,9 +376,6 @@ func (c *connection) idleTimeoutExpired() bool {
383376
}
384377
}
385378

386-
if !c.lifetimeDeadline.IsZero() && now.After(c.lifetimeDeadline) {
387-
return true
388-
}
389379
return false
390380
}
391381

x/mongo/driver/topology/connection_options.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ type connectionConfig struct {
4141
dialer Dialer
4242
handshaker Handshaker
4343
idleTimeout time.Duration
44-
lifeTimeout time.Duration
4544
cmdMonitor *event.CommandMonitor
4645
readTimeout time.Duration
4746
writeTimeout time.Duration
@@ -59,7 +58,6 @@ func newConnectionConfig(opts ...ConnectionOption) (*connectionConfig, error) {
5958
cfg := &connectionConfig{
6059
connectTimeout: 30 * time.Second,
6160
dialer: nil,
62-
lifeTimeout: 30 * time.Minute,
6361
tlsConnectionSource: defaultTLSConnectionSource,
6462
}
6563

@@ -136,14 +134,6 @@ func WithIdleTimeout(fn func(time.Duration) time.Duration) ConnectionOption {
136134
}
137135
}
138136

139-
// WithLifeTimeout configures the maximum life of a connection.
140-
func WithLifeTimeout(fn func(time.Duration) time.Duration) ConnectionOption {
141-
return func(c *connectionConfig) error {
142-
c.lifeTimeout = fn(c.lifeTimeout)
143-
return nil
144-
}
145-
}
146-
147137
// WithReadTimeout configures the maximum read time for a connection.
148138
func WithReadTimeout(fn func(time.Duration) time.Duration) ConnectionOption {
149139
return func(c *connectionConfig) error {

x/mongo/driver/topology/pool_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,13 +676,15 @@ func TestPool(t *testing.T) {
676676
MinPoolSize: 1,
677677
}
678678
maintainInterval = time.Second
679-
p, err := newPool(pc, WithDialer(func(Dialer) Dialer { return d }),
680-
WithLifeTimeout(func(time.Duration) time.Duration { return 10 * time.Millisecond }),
681-
)
679+
p, err := newPool(pc, WithDialer(func(Dialer) Dialer { return d }))
682680
maintainInterval = time.Minute
683681
noerr(t, err)
684682
err = p.connect()
685683
noerr(t, err)
684+
685+
// Increment the pool's generation number so the connection will be considered stale and will be closed by
686+
// get().
687+
p.clear()
686688
_, err = p.get(context.Background())
687689
noerr(t, err)
688690
})

0 commit comments

Comments
 (0)