-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[processor/k8sattributesprocessor] Leaking goroutine caused by invalid kube client init #30841
Comments
Pinging code owners:
See Adding Labels via Comments if you do not have permissions to add labels yourself. |
Initializing handling the goroutine in Start/Stop certainly seems like the best option. Good job catching this! |
This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping Pinging code owners:
See Adding Labels via Comments if you do not have permissions to add labels yourself. |
This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping Pinging code owners:
See Adding Labels via Comments if you do not have permissions to add labels yourself. |
Component(s)
processor/k8sattributes
Describe the issue you're reporting
Problem:
Relevant code:
opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/kube/client.go
Line 93 in 09884bd
The k8sattributesprocessor starts a goroutine when creating a new k8s client that is used for keeping the pod cache up to date. However, if the client initialization fails, the
New
method returns an error without a reference to the client. This results in a leaked goroutine as there's no way to stop the started goroutine.Proposed solution:
From my perspective, goroutines should not be started in
init
orNew
, butStart
instead. I think this is a much more accurate representation of behavior to users.I've implemented my proposed solution in #30842. Essentially, start the same goroutine inside
Start
, then use the existingpassthroughMode
configuration option to immediately return if the rest of the kube client's functionality is not necessary. This means the kubeclient should always be started and stopped, rather than conditionally. I think this is a cleaner UX for the kube client.Alternatives:
New
. This would mean callingc.Stop()
for every possible error in theNew
method. This seems error prone as it would be easy to forget adding theStop
call when adding a new error condition. I also don't believe it's idiomatic to create the goroutine inNew
as it's returning aClient
object, but the goroutine is running on aWatchClient
-specific method.The limiting factors here are that we want to start this goroutine for every kube client, and the
New
method returnsnil
for theClient
object if an error occurs.The text was updated successfully, but these errors were encountered: