Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix leaking go routine in docker stats fetching (#3492) #3514

Merged
merged 1 commit into from
Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Template, add newest changes here

=== Beats version HEAD
https://github.com/elastic/beats/compare/v5.1.1...master[Check the HEAD diff]
https://github.com/elastic/beats/compare/v5.2.0...master[Check the HEAD diff]

==== Breaking changes

Expand All @@ -33,6 +33,7 @@ https://github.com/elastic/beats/compare/v5.1.1...master[Check the HEAD diff]
*Heartbeat*

*Metricbeat*
- Fix go routine leak in docker module. {pull}3492[3492]

*Packetbeat*

Expand Down
14 changes: 8 additions & 6 deletions metricbeat/module/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down