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: prevent the goroutine leak from lb health checks #10

Merged
merged 1 commit into from
Aug 14, 2024

Conversation

utkuozdemir
Copy link
Member

We had a leak of goroutines where the lb.Start() failed due to a port conflict. The health check goroutines were never terminated, were waiting on the context.

This caused a leak of goroutines over a long time (as every failure on .Start() caused an exponential backoff) and increased CPU usage.

Fix this by calling lb.Close() even if starting the load balancer has failed.

Additionally, add the following features:

  • allow running an optional pprof server
  • allow specifying disallowed host port ranges to not be attempted to be proxied

Also rekres & bump deps.

We had a leak of goroutines where the `lb.Start()` failed due to a port conflict. The health check goroutines were never terminated, were waiting on the context.

This caused a leak of goroutines over a long time (as every failure on `.Start()` caused an exponential backoff) and increased CPU usage.

Fix this by calling `lb.Close()` even if starting the load balancer has failed.

Additionally, add the following features:
- allow running an optional pprof server
- allow specifying disallowed host port ranges to not be attempted to be proxied

Also rekres & bump deps.

Signed-off-by: Utku Ozdemir <[email protected]>
Comment on lines +135 to +137
// we still need to close the loadbalancer, so that the health checks goroutines get terminated
if closeErr := lb.Close(); closeErr != nil {
return errors.Join(fmt.Errorf("failed to start loadbalancer: %w", err), fmt.Errorf("failed to close loadbalancer: %w", closeErr))
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the actual fix of the goroutine leak

@utkuozdemir utkuozdemir marked this pull request as ready for review August 14, 2024 10:48
@utkuozdemir
Copy link
Member Author

/m

@talos-bot talos-bot merged commit a09759e into siderolabs:main Aug 14, 2024
14 checks passed
@utkuozdemir utkuozdemir deleted the fix-leak branch August 14, 2024 10:49
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.

4 participants