diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 0ec555b9ba7..7881992d321 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -40,6 +40,8 @@ https://github.com/elastic/beats/compare/v7.2.0...7.2[Check the HEAD diff] *Metricbeat* +- Fix connections leak in redis module {pull}12914[12914] + *Packetbeat* *Winlogbeat* diff --git a/metricbeat/module/redis/info/info.go b/metricbeat/module/redis/info/info.go index c7f9762d1e8..3580d53a6c8 100644 --- a/metricbeat/module/redis/info/info.go +++ b/metricbeat/module/redis/info/info.go @@ -50,8 +50,11 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { // Fetch fetches metrics from Redis by issuing the INFO command. func (m *MetricSet) Fetch(r mb.ReporterV2) error { + conn := m.Connection() + defer conn.Close() + // Fetch default INFO. - info, err := redis.FetchRedisInfo("default", m.Connection()) + info, err := redis.FetchRedisInfo("default", conn) if err != nil { return errors.Wrap(err, "failed to fetch redis info") } diff --git a/metricbeat/module/redis/key/key.go b/metricbeat/module/redis/key/key.go index 4cd8663adb8..085729678ca 100644 --- a/metricbeat/module/redis/key/key.go +++ b/metricbeat/module/redis/key/key.go @@ -70,6 +70,8 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { // Fetch fetches information from Redis keys func (m *MetricSet) Fetch(r mb.ReporterV2) error { conn := m.Connection() + defer conn.Close() + for _, p := range m.patterns { if err := redis.Select(conn, p.Keyspace); err != nil { msg := errors.Wrapf(err, "Failed to select keyspace %d", p.Keyspace) diff --git a/metricbeat/module/redis/keyspace/keyspace.go b/metricbeat/module/redis/keyspace/keyspace.go index 73172e05f97..3f2f0381846 100644 --- a/metricbeat/module/redis/keyspace/keyspace.go +++ b/metricbeat/module/redis/keyspace/keyspace.go @@ -48,8 +48,11 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { // Fetch fetches metrics from Redis by issuing the INFO command. func (m *MetricSet) Fetch(r mb.ReporterV2) error { + conn := m.Connection() + defer conn.Close() + // Fetch default INFO. - info, err := redis.FetchRedisInfo("keyspace", m.Connection()) + info, err := redis.FetchRedisInfo("keyspace", conn) if err != nil { return errors.Wrap(err, "Failed to fetch redis info for keyspaces") }