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

Merged
merged 1 commit into from
Jan 31, 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
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*

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