Skip to content

Commit d0c1f47

Browse files
committed
Fix connection leakage in dispatch and cursors
GODRIVER-397 Change-Id: Ia10bf4db82c78c85357437a0882bdccce499e0c2
1 parent 68b1723 commit d0c1f47

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

core/dispatch/distinct.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func Distinct(
4444
if err != nil {
4545
return result.Distinct{}, err
4646
}
47+
defer conn.Close()
4748

4849
return cmd.RoundTrip(ctx, desc, conn)
4950
}

core/topology/cursor.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ func (c *cursor) Close(ctx context.Context) error {
131131

132132
_, err = (&command.KillCursors{NS: c.namespace, IDs: []int64{c.id}}).RoundTrip(ctx, c.server.SelectedDescription(), conn)
133133
if err != nil {
134+
_ = conn.Close() // The command response error is more important here
134135
return err
135136
}
136137

@@ -155,6 +156,7 @@ func (c *cursor) getMore(ctx context.Context) {
155156

156157
response, err := (&command.GetMore{ID: c.id, NS: c.namespace, Opts: c.opts}).RoundTrip(ctx, c.server.SelectedDescription(), conn)
157158
if err != nil {
159+
_ = conn.Close() // The command response error is more important here
158160
c.err = err
159161
return
160162
}

0 commit comments

Comments
 (0)