Skip to content

Conversation

cvvz
Copy link
Member

@cvvz cvvz commented Apr 16, 2025

What type of PR is this?
/kind bug

What this PR does / why we need it:
fix: goroutine leak when timeout

The write operation to a channel in Go is blocking unless there is a receiver waiting for it, this means after WaitUntilTimeout exit, the goroutine will remain stuck at done <- true forever.
After changed to buffered channel, even if there is no receiver, done <- true can successfully write and continue.

Which issue(s) this PR fixes:

Fixes #

Requirements:

Special notes for your reviewer:

Release note:

fix: goroutine leak when timeout

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 16, 2025
@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Apr 16, 2025
@cvvz
Copy link
Member Author

cvvz commented Apr 16, 2025

Btw, for WaitUntilTimeout, I think k8s lib has similar implementation, why do we implement this from scratch?

func WaitUntilTimeout(timeout time.Duration, execFunc ExecFunc, timeoutFunc TimeoutFunc) error {
// Create a channel to receive the result of the azcopy exec function
done := make(chan bool)
done := make(chan bool, 1)
Copy link
Member

Choose a reason for hiding this comment

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

why set buffer size as 1 would fix the issue?

Copy link
Member Author

Choose a reason for hiding this comment

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

The write operation to a channel in Go is blocking unless there is a receiver waiting for it, this means after WaitUntilTimeout exit, the goroutine will remain stuck at done <- true forever.
After changed to buffered channel, even if there is no receiver, done <- true can successfully write and continue.

@andyzhangx
Copy link
Member

Btw, for WaitUntilTimeout, I think k8s lib has similar implementation, why do we implement this from scratch?

we could use k8s lib if there is a suitable function, any recommendation?

@andyzhangx
Copy link
Member

Btw, for WaitUntilTimeout, I think k8s lib has similar implementation, why do we implement this from scratch?

we could use k8s lib if there is a suitable function, any recommendation?

we should use wait.PollUntilContextTimeout func

@andyzhangx
Copy link
Member

this WaitUntilTimeout is different from func PollUntilContextTimeout(ctx context.Context, interval, timeout time.Duration, immediate bool, condition ConditionWithContextFunc), that's the reason we write a new function.

Copy link
Member

@andyzhangx andyzhangx left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 16, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andyzhangx, cvvz

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

The pull request process is described here

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 16, 2025
@andyzhangx andyzhangx merged commit 2b31e9c into kubernetes-sigs:master Apr 16, 2025
21 of 22 checks passed
@andyzhangx
Copy link
Member

/cherrypick release-1.32

@andyzhangx
Copy link
Member

/cherrypick release-1.31

@andyzhangx
Copy link
Member

/cherrypick release-1.30

@andyzhangx
Copy link
Member

/cherrypick release-1.26

@andyzhangx
Copy link
Member

/cherrypick release-1.25

@andyzhangx
Copy link
Member

/cherrypick release-1.24

@k8s-infra-cherrypick-robot

@andyzhangx: cannot checkout release-1.32: error checking out "release-1.32": exit status 1 error: pathspec 'release-1.32' did not match any file(s) known to git

In response to this:

/cherrypick release-1.32

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.

@k8s-infra-cherrypick-robot

@andyzhangx: cannot checkout release-1.31: error checking out "release-1.31": exit status 1 error: pathspec 'release-1.31' did not match any file(s) known to git

In response to this:

/cherrypick release-1.31

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.

@k8s-infra-cherrypick-robot

@andyzhangx: cannot checkout release-1.30: error checking out "release-1.30": exit status 1 error: pathspec 'release-1.30' did not match any file(s) known to git

In response to this:

/cherrypick release-1.30

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.

@k8s-infra-cherrypick-robot

@andyzhangx: #1947 failed to apply on top of branch "release-1.26":

Applying: fix: goroutine leak when timeout
Using index info to reconstruct a base tree...
M	go.mod
M	vendor/modules.txt
Falling back to patching base and 3-way merge...
Auto-merging vendor/modules.txt
CONFLICT (content): Merge conflict in vendor/modules.txt
Auto-merging go.mod
CONFLICT (content): Merge conflict in go.mod
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"
Patch failed at 0001 fix: goroutine leak when timeout

In response to this:

/cherrypick release-1.26

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.

@k8s-infra-cherrypick-robot

@andyzhangx: #1947 failed to apply on top of branch "release-1.25":

Applying: fix: goroutine leak when timeout
Using index info to reconstruct a base tree...
M	go.mod
M	pkg/util/util.go
M	pkg/util/util_test.go
M	vendor/modules.txt
Falling back to patching base and 3-way merge...
Auto-merging vendor/modules.txt
CONFLICT (content): Merge conflict in vendor/modules.txt
Auto-merging pkg/util/util_test.go
Auto-merging pkg/util/util.go
Auto-merging go.mod
CONFLICT (content): Merge conflict in go.mod
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"
Patch failed at 0001 fix: goroutine leak when timeout

In response to this:

/cherrypick release-1.25

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.

@k8s-infra-cherrypick-robot

@andyzhangx: #1947 failed to apply on top of branch "release-1.24":

Applying: fix: goroutine leak when timeout
Using index info to reconstruct a base tree...
M	go.mod
M	pkg/util/util.go
M	pkg/util/util_test.go
M	vendor/modules.txt
Falling back to patching base and 3-way merge...
Auto-merging vendor/modules.txt
CONFLICT (content): Merge conflict in vendor/modules.txt
Auto-merging pkg/util/util_test.go
Auto-merging pkg/util/util.go
Auto-merging go.mod
CONFLICT (content): Merge conflict in go.mod
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"
Patch failed at 0001 fix: goroutine leak when timeout

In response to this:

/cherrypick release-1.24

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.

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants