From 956727161e0d765d1546fb8be46cbed1ec061fe4 Mon Sep 17 00:00:00 2001 From: Eric Daniels Date: Tue, 1 Nov 2022 19:29:31 -0400 Subject: [PATCH] GODRIVER-2631 - Always close internal.DefaultHTTPClient on Client.Disconnect (#1114) --- mongo/client.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mongo/client.go b/mongo/client.go index b1ce77129a..d80fd1d55e 100644 --- a/mongo/client.go +++ b/mongo/client.go @@ -281,6 +281,10 @@ func (c *Client) Disconnect(ctx context.Context) error { ctx = context.Background() } + if c.httpClient == internal.DefaultHTTPClient { + defer internal.CloseIdleHTTPConnections(c.httpClient) + } + c.endSessions(ctx) if c.mongocryptdFLE != nil { if err := c.mongocryptdFLE.disconnect(ctx); err != nil { @@ -312,10 +316,6 @@ func (c *Client) Disconnect(ctx context.Context) error { return replaceErrors(disconnector.Disconnect(ctx)) } - if c.httpClient == internal.DefaultHTTPClient { - internal.CloseIdleHTTPConnections(c.httpClient) - } - return nil }