Skip to content

fix(k8s): prevent goroutine leak and deadlock in pod watcher#3883

Open
vishwas-droid wants to merge 3 commits into
knative:mainfrom
vishwas-droid:fix-k8s-watcher-leak
Open

fix(k8s): prevent goroutine leak and deadlock in pod watcher#3883
vishwas-droid wants to merge 3 commits into
knative:mainfrom
vishwas-droid:fix-k8s-watcher-leak

Conversation

@vishwas-droid
Copy link
Copy Markdown

Changes

  • 🐛 Fixed a critical goroutine leak inside runWithVolumeMounted by making the pod watcher loop context-aware (<-localCtx.Done()).
  • 🐛 Prevented potential deadlocks/infinite hangs by introducing an errCh to handle abrupt or unexpected watch channel closures from the Kubernetes API server.
  • 🧹 Cleaned up a double type assertion on event.Object to eliminate any sudden runtime panic risks when unexpected object states are encountered.

/kind bug

Release Note

Fixed a potential goroutine leak and deadlock scenario in the Kubernetes pod watcher inside `pkg/k8s`.

Signed-off-by: vishwas-droid <vishwasbajaj.global@gmail.com>
@knative-prow knative-prow Bot added the kind/bug Bugs label Jun 6, 2026
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Jun 6, 2026

CLA Not Signed

@knative-prow knative-prow Bot requested review from dsimansk and jrangelramos June 6, 2026 16:02
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented Jun 6, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: vishwas-droid
Once this PR has been reviewed and has the lgtm label, please assign gauron99 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented Jun 6, 2026

Welcome @vishwas-droid! It looks like this is your first PR to knative/func 🎉

@knative-prow knative-prow Bot added size/M 🤖 PR changes 30-99 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels Jun 6, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented Jun 6, 2026

Hi @vishwas-droid. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Kubernetes pod watcher logic in pkg/k8s to avoid goroutine leaks and hangs while waiting for a pod’s container termination state during runWithVolumeMounted.

Changes:

  • Made the watcher goroutine context-aware so it can exit promptly on cancellation.
  • Added an error channel to surface unexpected watch channel closure from the API server.
  • Removed a redundant/dangerous double type assertion on event.Object to reduce panic risk.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/k8s/persistent_volumes.go
Comment thread pkg/k8s/persistent_volumes.go Outdated
@matejvasek
Copy link
Copy Markdown
Contributor

/ok-to-test

@knative-prow knative-prow Bot added ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test 🤖 Needs an org member to approve testing labels Jun 7, 2026
@vishwas-droid
Copy link
Copy Markdown
Author

@matejvasek Addressed the Copilot suggestion. PTAL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Bugs ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. size/M 🤖 PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants