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

CSI fix for gRPC conn leak #64519

Merged
merged 1 commit into from Jun 2, 2018
Merged

CSI fix for gRPC conn leak #64519

merged 1 commit into from Jun 2, 2018

Conversation

vladimirvivien
Copy link
Member

@vladimirvivien vladimirvivien commented May 30, 2018

What this PR does / why we need it:
This PR is a bug fix for leaky gRPC connection that never closes (see issue #64341 for detail)

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #64341

This fix was originally started with PR #64380

Fixed CSI gRPC connection leak during volume operations.

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels May 30, 2018
@vladimirvivien
Copy link
Member Author

/sig storage
/kind bug

@k8s-ci-robot k8s-ci-robot added sig/storage Categorizes an issue or PR as relevant to SIG Storage. kind/bug Categorizes issue or PR as related to a bug. labels May 30, 2018
@dims
Copy link
Member

dims commented May 30, 2018

/milestone v1.11
/sig storage
/priority important-soon

@kubernetes/sig-storage-pr-reviews please see if the milestone/priority is correct

@k8s-ci-robot k8s-ci-robot added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label May 30, 2018
@k8s-ci-robot k8s-ci-robot added this to the v1.11 milestone May 30, 2018
@vladimirvivien
Copy link
Member Author

/test pull-kubernetes-e2e-kops-aws

@vladimirvivien vladimirvivien changed the title CSI fix for gRPC conn leak, test updates CSI fix for gRPC conn leak May 30, 2018
return nil, fmt.Errorf("driver name is empty")
}

network := "unix"
Copy link
Contributor

Choose a reason for hiding this comment

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

What about defining network as a const at the top of the file? I think it would be more visible.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about it, the value for network does not need to be global since it should always be "unix" and is only used when constructing the connection in that method.

Copy link
Member

@saad-ali saad-ali left a comment

Choose a reason for hiding this comment

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

Some minor comments

@@ -61,45 +62,13 @@ type csiClient interface {

// csiClient encapsulates all csi-plugin methods
type csiDriverClient struct {
Copy link
Member

Choose a reason for hiding this comment

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

Add a struct interface implementation check:

var _ csiClient = &csiDriverClient{}

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

if err := c.assertConnection(); err != nil {
glog.Errorf("%v: failed to assert a connection: %v", csiPluginName, err)

conn, err := newGrpcConn(c.driverName)
Copy link
Member

Choose a reason for hiding this comment

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

nit: as a general rule of thumb never call new anything inside of a method implementing business logic. That encodes the creation of a dependency with the business logic making it harder to test just the business logic.

Instead, have the dependency either passed in as a parameter (with an interface type) or make the method creating the external dependency another interface method (i.e. a new NewGrpcConnection() method in the csiClient interface). That way it makes it easy to create a fake of the dependency for testing.

You don't have to do this now. Can do it in a follow up PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok I will take a look at that.

Copy link
Member Author

Choose a reason for hiding this comment

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

i looked at your suggestion. While agree, I even had an impl that injected the connection. However, the grpc.ClientConn type (created with newGrpcCon) is a struct value which complicates mocking it. So, I kept it simple. But I agree.

@@ -290,29 +291,12 @@ func (c *csiMountMgr) TearDownAt(dir string) error {
return nil
}

// load volume info from file
Copy link
Member

Choose a reason for hiding this comment

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

Why is this code being moved to NewUnmounter()?

Copy link
Member

Choose a reason for hiding this comment

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

Follow up, why isn't saveVolumeData(...) also being moved?

Copy link
Member Author

Choose a reason for hiding this comment

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

initialization of csiClient is moved to New{Moun|Unmoun}ter to keep value injection of csiMounterMgr consistent and in one location, where possible. This also helps clean the method of non-storage code. I agree, saveVolumeData probably should be moved.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, saveVolumeData will stay. This is because it's called in the SetUpAt() method after the mount dir its created which is the location where the json file is saved.

Copy link
Member

Choose a reason for hiding this comment

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

Let's open up a an issue to clean this up later. It's really odd that save is done in one location and load is done in a completely different place.

Copy link
Member Author

Choose a reason for hiding this comment

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

Once you pointed it out, I could not resist to make things more uniformed. Good suggestion (included a bit of clean up too) Done.

@vladimirvivien
Copy link
Member Author

/test pull-kubernetes-e2e-gce-device-plugin-gpu
/test pull-kubernetes-e2e-gce

@vladimirvivien
Copy link
Member Author

/test pull-kubernetes-e2e-gce

@vladimirvivien
Copy link
Member Author

/test pull-kubernetes-e2e-gce-device-plugin-gpu

Copy link
Member

@saad-ali saad-ali left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve


return nil
func newCsiDriverClient(driverName string) *csiDriverClient {
Copy link
Member

Choose a reason for hiding this comment

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

nit: return the interface (csiClient) not the struct

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right. I missed that.

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: saad-ali, vladimirvivien

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

@dims
Copy link
Member

dims commented Jun 1, 2018

/status approved-for-milestone

@k8s-github-robot
Copy link

[MILESTONENOTIFIER] Milestone Pull Request: Up-to-date for process

@saad-ali @vladimirvivien

Pull Request Labels
  • sig/storage: Pull Request will be escalated to these SIGs if needed.
  • priority/important-soon: Escalate to the pull request owners and SIG owner; move out of milestone after several unsuccessful escalation attempts.
  • kind/bug: Fixes a bug discovered during the current release.
Help

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 54900d7 into kubernetes:master Jun 2, 2018
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Jun 4, 2018
k8s-github-robot pushed a commit that referenced this pull request Jun 4, 2018
…f-#64519-upstream-release-1.10

Automatic merge from submit-queue.

Automated cherry pick of #64519: CSI fix for gRPC conn leak, test updates

Cherry pick of #64519 on release-1.10.

#64519: CSI fix for gRPC conn leak, test updates

```release-note
Fixed CSI gRPC connection leak during volume operations.
```
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. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/storage Categorizes an issue or PR as relevant to SIG Storage. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

In-tree CSI Plugin leaking gRPC connections
6 participants