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

Failing closed after maximum retry is achieved to avoid inf recursion #336

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

knabben
Copy link

@knabben knabben commented Apr 16, 2024

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line:

/kind api-change
/kind bug
/kind cleanup
/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake
/kind bug

What this PR does / why we need it:
Adding a maximum retry for the CSI to find the volume target from a mountpath.

Which issue(s) this PR fixes:

Fixes #193

Special notes for your reviewer:
Tracking the recursion call trace here:
#193 (comment)

Does this PR introduce a user-facing change?:

Maximum retry (3) when for the getTarget method iterate and find the correct volume of the mount path. 

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. 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, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

The full list of commands accepted by this bot can be found 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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 16, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @knabben. Thanks for your PR.

I'm waiting for a kubernetes-csi 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.

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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 16, 2024
@knabben
Copy link
Author

knabben commented Apr 16, 2024

/assign @mauriciopoppe

"testing"
)

func TestGetTarget(t *testing.T) {
Copy link
Author

Choose a reason for hiding this comment

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

This (and other calls) needs a real coverage

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, it'd be hard to setup a scenario with symlinks so that (Get-Item -Path $Env:mountpath).Target works though.

@jsturtevant
Copy link
Contributor

/ok-to-test

@k8s-ci-robot
Copy link
Contributor

@jsturtevant: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/ok-to-test

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/test-infra repository.

@mauriciopoppe
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 25, 2024
@@ -268,7 +271,8 @@ func (VolumeAPI) GetDiskNumberFromVolumeID(volumeID string) (uint32, error) {

// GetVolumeIDFromTargetPath - gets the volume ID given a mount point, the function is recursive until it find a volume or errors out
func (VolumeAPI) GetVolumeIDFromTargetPath(mount string) (string, error) {
volumeString, err := getTarget(mount)
var initialRetry = 1
Copy link
Member

Choose a reason for hiding this comment

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

Nit: it could be just 0

@@ -54,6 +54,9 @@ var (
// PS C:\disks> (Get-Disk -Number 1 | Get-Partition | Get-Volume).UniqueId
// \\?\Volume{452e318a-5cde-421e-9831-b9853c521012}\
VolumeRegexp = regexp.MustCompile(`Volume\{[\w-]*\}`)

// MaxGetTargetRetry defines the number of retries trying to get the correct volume target
MaxGetTargetRetry = 3
Copy link
Member

Choose a reason for hiding this comment

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

I think 3 is a very low number, in previous symlink dereferencing code I think we used 256 or maybe I read that in https://github.com/cyphar/filepath-securejoin/blob/main/join.go#L57

What about inlining the value where it's used?

cmd := `(Get-Item -Path $Env:mountpath).Target`
cmdEnv := fmt.Sprintf("mountpath=%s", mount)
out, err := utils.RunPowershellCmd(cmd, cmdEnv)
if err != nil || len(out) == 0 {
return "", fmt.Errorf("error getting volume from mount. cmd: %s, output: %s, error: %v", cmd, string(out), err)
if err != nil || len(out) == 0 || retry >= MaxGetTargetRetry {
Copy link
Member

Choose a reason for hiding this comment

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

As an alternative we can hardcode it to retry == 256

}

return ensureVolumePrefix(volumeString), nil
}

// GetVolumeIDFromTargetPath returns the volume id of a given target path.
// GetClosestVolumeIDFromTargetPath returns the volume id of a given target path.
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for fixing this!

cmd := `(Get-Item -Path $Env:mountpath).Target`
cmdEnv := fmt.Sprintf("mountpath=%s", mount)
out, err := utils.RunPowershellCmd(cmd, cmdEnv)
if err != nil || len(out) == 0 {
return "", fmt.Errorf("error getting volume from mount. cmd: %s, output: %s, error: %v", cmd, string(out), err)
if err != nil || len(out) == 0 || retry >= MaxGetTargetRetry {
Copy link
Member

Choose a reason for hiding this comment

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

We can have many ifs, that way we know which was the actual reason e.g.

if err != nil {
   // error message
}

if len(out) == 0 {
   // no length error message
}

if retry == 256 {
   // max recursion reached error message
}

"testing"
)

func TestGetTarget(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Agreed, it'd be hard to setup a scenario with symlinks so that (Get-Item -Path $Env:mountpath).Target works though.

}

Copy link
Member

Choose a reason for hiding this comment

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

For debugging purposes of #193 (comment) maybe you could add

klog.V(8).Infof("retry: %d, volumeString: %s", retry, volumeString)

And start the server with very high verbosity

@k8s-ci-robot
Copy link
Contributor

@knabben: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubernetes-csi-csi-proxy-integration 9740ee2 link true /test pull-kubernetes-csi-csi-proxy-integration

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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/test-infra repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

High cpu usage of powershell processes triggered by csi-proxy
4 participants