From a64b4c79ad0b8aa9ae4642508eb6b75ddb1d87f6 Mon Sep 17 00:00:00 2001 From: Nicolas Ruflin Date: Wed, 29 Nov 2017 11:50:09 +1100 Subject: [PATCH] fix connection leak in the mongodb module (#5711) (#5742) Signed-off-by: Shijiang Wei (cherry picked from commit f9a18c16ae099d67500229dc80af13b6dd621662) --- CHANGELOG.asciidoc | 1 + metricbeat/module/mongodb/dbstats/dbstats.go | 1 + metricbeat/module/mongodb/status/status.go | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 182599b0054..37f30c235f5 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -43,6 +43,7 @@ https://github.com/elastic/beats/compare/v6.0.0...master[Check the HEAD diff] *Metricbeat* - Fix map overwrite in docker diskio module. {issue}5582[5582] +- Fix connection leak in mongodb module. {issue}5688[5688] *Packetbeat* diff --git a/metricbeat/module/mongodb/dbstats/dbstats.go b/metricbeat/module/mongodb/dbstats/dbstats.go index a9b8a1da01e..d1312ede0d2 100644 --- a/metricbeat/module/mongodb/dbstats/dbstats.go +++ b/metricbeat/module/mongodb/dbstats/dbstats.go @@ -61,6 +61,7 @@ func (m *MetricSet) Fetch() ([]common.MapStr, error) { if err != nil { return nil, err } + defer mongoSession.Close() // Get the list of databases names, which we'll use to call db.stats() on each dbNames, err := mongoSession.DatabaseNames() diff --git a/metricbeat/module/mongodb/status/status.go b/metricbeat/module/mongodb/status/status.go index f25229077d9..84e3f27f346 100644 --- a/metricbeat/module/mongodb/status/status.go +++ b/metricbeat/module/mongodb/status/status.go @@ -59,6 +59,7 @@ func (m *MetricSet) Fetch() (common.MapStr, error) { if err != nil { return nil, err } + defer mongoSession.Close() result := map[string]interface{}{} if err := mongoSession.DB("admin").Run(bson.D{{Name: "serverStatus", Value: 1}}, &result); err != nil {