From 0f758b4c1a232274272c70299e3e1f6c6e594e05 Mon Sep 17 00:00:00 2001 From: ruflin Date: Mon, 30 Jan 2017 16:06:55 +0100 Subject: [PATCH] Fix leaking go routine in docker stats fetching Go routine on line 79 never stopped as queue was not closed. Fixes https://github.com/elastic/beats/issues/3489 --- CHANGELOG.asciidoc | 1 + metricbeat/module/docker/docker.go | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 678caecde7c..8f397999e24 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -37,6 +37,7 @@ https://github.com/elastic/beats/compare/v5.1.1...master[Check the HEAD diff] - Kafka module case sensitive host name matching. {pull}3193[3193] - Fix interface conversion panic in couchbase module {pull}3272[3272] - Fix overwriting explicit empty config sections {issue}2918[2918] +- Fix go routine leak in docker module. {pull}3492[3492] *Packetbeat* diff --git a/metricbeat/module/docker/docker.go b/metricbeat/module/docker/docker.go index 67437eef1b8..79aa42988da 100644 --- a/metricbeat/module/docker/docker.go +++ b/metricbeat/module/docker/docker.go @@ -66,24 +66,26 @@ func FetchStats(client *docker.Client) ([]Stat, error) { var wg sync.WaitGroup - containersList := []Stat{} + containersList := make([]Stat, 0, len(containers)) queue := make(chan Stat, 1) wg.Add(len(containers)) for _, container := range containers { go func(container docker.APIContainers) { + defer wg.Done() queue <- exportContainerStats(client, &container) }(container) } go func() { - for container := range queue { - containersList = append(containersList, container) - wg.Done() - } + wg.Wait() + close(queue) }() - wg.Wait() + // This will break after the queue has been drained and queue is closed. + for container := range queue { + containersList = append(containersList, container) + } return containersList, err }