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

[kube-proxy/ipvs] Protect Netlink calls with a mutex #72361

Merged
merged 1 commit into from
Dec 27, 2018

Conversation

lbernail
Copy link
Contributor

@lbernail lbernail commented Dec 27, 2018

What type of PR is this?
/kind bug

What this PR does / why we need it:
We have a race condition between the proxier and the gracefulTerminationManager goroutines: when both use the netlink socket at the same time we can end up in a deadlock. This PR protects netlink calls with a mutex to make sure a single goroutine is using the socket at any given time.
An alternative would be to use two different sockets but it is probably safer to avoid parallel netlink calls.
Not sure if this is the best design, happy to discuss it.

Which issue(s) this PR fixes:
Fixes #71071

Special notes for your reviewer:
Currently being tested by users that reported the issue (more details in #71071)

Does this PR introduce a user-facing change?:

Fix race condition introduced by graceful termination which can lead to a deadlock in kube-proxy

/sig network
/area ipvs
/assign @m1093782566

@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. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. sig/network Categorizes an issue or PR as relevant to SIG Network. area/ipvs cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Dec 27, 2018
@k8s-ci-robot
Copy link
Contributor

Hi @lbernail. Thanks for your PR.

I'm waiting for a kubernetes 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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Dec 27, 2018
@m1093782566
Copy link
Contributor

/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 Dec 27, 2018
@m1093782566
Copy link
Contributor

I am open to discuss the two-sockets approach, but I think we should fix the dead-lock issue first. Obviously, this PR can avoid dead lock.

@m1093782566
Copy link
Contributor

/lgtm

/approve

Let's see...

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lbernail, m1093782566

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 Dec 27, 2018
@k8s-ci-robot k8s-ci-robot merged commit bb7973a into kubernetes:master Dec 27, 2018
ipvsSvc, err := runner.ipvsHandle.GetService(svc)
runner.mu.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use 'defer' ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could get the lock at the beginning of each function and use defer everywhere to make everything consistent. I chose to release the lock as quickly as possible. We do not need to keep the lock to call toVirtualServer in GetVirtualServer for instance.

I'm completely open to changing this if it makes the code easier to read and the optimization is not worth it.

Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if GetService() encounters error ?
I am yet to get familiar with Go lang. Not sure if the unlocking would be skipped in some situation.

Choose a reason for hiding this comment

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

The error is returned as a value, and only inspected after unlocking, so the mutex will be released in any case.

Copy link
Contributor

Choose a reason for hiding this comment

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

True.

k8s-ci-robot added a commit that referenced this pull request Jan 4, 2019
…1-upstream-release-1.12

Automated cherry pick of #72361 upstream release 1.12
k8s-ci-robot added a commit that referenced this pull request Jan 4, 2019
…1-upstream-release-1.11

Automated cherry pick of #72361 upstream release 1.11
k8s-ci-robot added a commit that referenced this pull request Jan 5, 2019
…1-upstream-release-1.13

Automated cherry pick of #72361 upstream release 1.13
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. area/ipvs 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. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. 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. sig/network Categorizes an issue or PR as relevant to SIG Network. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kube-proxy ipvs mode hangs after a few hours, needs manual restart
5 participants