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

bug: fix goroutine leaks caused by incorrect usage of WatchCh #14916

Merged
merged 1 commit into from
Oct 13, 2022

Conversation

boxofrad
Copy link
Contributor

@boxofrad boxofrad commented Oct 7, 2022

Description

memdb's WatchCh method creates a goroutine that will publish to the returned channel when the watchset is triggered or the given context is canceled. Although this is called out in its godoc comment, it's not obvious that this method creates a goroutine who's lifecycle you need to manage.

In the xDS capacity controller, we were calling WatchCh on each iteration of the control loop, meaning the number of goroutines would grow on each autopilot event until there was catalog churn.

In the catalog config source, we were calling WatchCh with the background context, meaning that the goroutine would keep running after the sync loop had terminated.

@boxofrad boxofrad requested a review from riddhi89 October 7, 2022 11:44
@boxofrad boxofrad force-pushed the boxofrad/incorrect-watchch-usage branch 2 times, most recently from 5558acd to 2b903a9 Compare October 7, 2022 11:50
Copy link
Contributor

@riddhi89 riddhi89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! LGTM

memdb's `WatchCh` method creates a goroutine that will publish to the
returned channel when the watchset is triggered or the given context
is canceled. Although this is called out in its godoc comment, it's
not obvious that this method creates a goroutine who's lifecycle you
need to manage.

In the xDS capacity controller, we were calling `WatchCh` on each
iteration of the control loop, meaning the number of goroutines would
grow on each autopilot event until there was catalog churn.

In the catalog config source, we were calling `WatchCh` with the
background context, meaning that the goroutine would keep running after
the sync loop had terminated.
@boxofrad boxofrad force-pushed the boxofrad/incorrect-watchch-usage branch from 2b903a9 to 41aa607 Compare October 11, 2022 16:44
@boxofrad boxofrad merged commit 0af9f16 into main Oct 13, 2022
@boxofrad boxofrad deleted the boxofrad/incorrect-watchch-usage branch October 13, 2022 11:04
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.

3 participants