Skip to content

Commit 489a24b

Browse files
authored
PMM-13426: close connections on failure (#1039)
1 parent 82fef20 commit 489a24b

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

pbm/connect/connect.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ func Connect(ctx context.Context, uri, appName string) (*clientImpl, error) {
201201

202202
inf, err := getNodeInfo(ctx, client)
203203
if err != nil {
204+
_ = client.Disconnect(ctx)
204205
return nil, errors.Wrap(err, "get NodeInfo")
205206
}
206207
if inf.isMongos() {
@@ -212,6 +213,7 @@ func Connect(ctx context.Context, uri, appName string) (*clientImpl, error) {
212213

213214
inf.Opts, err = getMongodOpts(ctx, client, nil)
214215
if err != nil {
216+
_ = client.Disconnect(ctx)
215217
return nil, errors.Wrap(err, "get mongod options")
216218
}
217219

@@ -224,6 +226,7 @@ func Connect(ctx context.Context, uri, appName string) (*clientImpl, error) {
224226

225227
csvr, err := getConfigsvrURI(ctx, client)
226228
if err != nil {
229+
_ = client.Disconnect(ctx)
227230
return nil, errors.Wrap(err, "get config server connection URI")
228231
}
229232
// no need in this connection anymore, we need a new one with the ConfigServer

0 commit comments

Comments
 (0)