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

Fix race condition in GetCurrentNS temporarily #1131

Merged
merged 1 commit into from
Aug 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion pkg/agent/cniserver/interface_configuration_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cniserver
import (
"fmt"
"net"
"runtime"
"time"

"github.com/Mellanox/sriovnet"
Expand Down Expand Up @@ -194,7 +195,22 @@ func (ic *ifConfigurator) configureContainerLinkVeth(
hostIface := &current.Interface{Name: hostIfaceName}
containerIface := &current.Interface{Name: containerIfaceName, Sandbox: containerNetNS}
result.Interfaces = []*current.Interface{hostIface, containerIface}
if err := ns.WithNetNSPath(containerNetNS, func(hostNS ns.NetNS) error {

// This is a workaround for issue #1113, which is caused by https://github.com/containernetworking/plugins/issues/524.
// Instead of using the provided netns argument, which might not be the real hostNS, it fixes it by getting the
Copy link
Contributor

Choose a reason for hiding this comment

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

it fixes by getting -> this fix gets

Copy link
Contributor

Choose a reason for hiding this comment

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

@jianjuns I think "it fixes it" is correct here, even though I like your suggestion better. However, since this is your only comment and Quan may have started his weekend, I will merge this and proceed with the 0.9.1 release.

Copy link
Contributor

Choose a reason for hiding this comment

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

No problem to me.

// hostNS in advance with the OS thread locked.
// TODO: remove this once the upstream issue is fixed.
hostNS, err := func() (ns.NetNS, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
return ns.GetCurrentNS()
}()
if err != nil {
return fmt.Errorf("failed to get host netns: %v", err)
}
defer hostNS.Close()

if err := ns.WithNetNSPath(containerNetNS, func(_ ns.NetNS) error {
klog.V(2).Infof("Creating veth devices (%s, %s) for container %s", containerIfaceName, hostIfaceName, containerID)
hostVeth, containerVeth, err := ip.SetupVethWithName(containerIfaceName, hostIfaceName, mtu, hostNS)
if err != nil {
Expand Down