Skip to content

Commit f456f72

Browse files
Divjot AroraIsabella Siu
authored andcommitted
Replace nil context with context.Background in Client Disconnect.
GODRIVER-767 Change-Id: I9f63d169a1bdf8ef2e7c0d355f29a83cc96f0661
1 parent 33f5dc2 commit f456f72

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

mongo/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ func (c *Client) Connect(ctx context.Context) error {
100100
// or write operations. If this method returns with no errors, all connections
101101
// associated with this Client have been closed.
102102
func (c *Client) Disconnect(ctx context.Context) error {
103+
if ctx == nil {
104+
ctx = context.Background()
105+
}
106+
103107
c.endSessions(ctx)
104108
return replaceTopologyErr(c.topology.Disconnect(ctx))
105109
}

mongo/client_internal_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,3 +538,13 @@ func TestClient_Ping_InvalidHost(t *testing.T) {
538538
err = c.Ping(ctx, nil)
539539
require.NotNil(t, err)
540540
}
541+
542+
func TestClient_Disconnect_NilContext(t *testing.T) {
543+
cs := testutil.ConnString(t)
544+
c, err := NewClient(cs.String())
545+
require.NoError(t, err)
546+
err = c.Connect(nil)
547+
require.NoError(t, err)
548+
err = c.Disconnect(nil)
549+
require.NoError(t, err)
550+
}

0 commit comments

Comments
 (0)