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 memory leak in stats collector #3069

Merged
merged 1 commit into from
Oct 27, 2021
Merged

Conversation

angelcar
Copy link
Contributor

@angelcar angelcar commented Oct 26, 2021

Summary

This addresses #2865 where a goroutine leak was slowly increasing memory consumption.

Implementation details

dockerGoClient.Stats creates a <-chan *types.StatsJSON which is never closed, therefore the send operation statsC <- data blocks for ever, which in turn keeps the corresponding goroutine alive for ever.

The solution is to simply do a send operation, but returning if the context (used to invoke Stats) is cancelled. This ends the offending goroutine.

i.e.

select {
case <-ctx.Done():
	return
case statsC <- data:
}

Testing

Test in a long-lived cluster and verify memory is no longer increasing indefinitely.

New tests cover the changes: yes

Description for the changelog

Bug - Fixes #2865 caused by a memory leak in stats collector.

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@angelcar angelcar marked this pull request as ready for review October 26, 2021 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants