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 watchMiss thread context #2051

Merged
merged 1 commit into from
Jan 11, 2018
Merged
Show file tree
Hide file tree
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
20 changes: 18 additions & 2 deletions drivers/overlay/ov_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ func (n *network) initSandbox(restore bool) error {
n.setNetlinkSocket(nlSock)

if err == nil {
go n.watchMiss(nlSock)
go n.watchMiss(nlSock, key)
} else {
logrus.Errorf("failed to subscribe to neighbor group netlink messages for overlay network %s in sbox %s: %v",
n.id, sbox.Key(), err)
Expand All @@ -720,7 +720,23 @@ func (n *network) initSandbox(restore bool) error {
return nil
}

func (n *network) watchMiss(nlSock *nl.NetlinkSocket) {
func (n *network) watchMiss(nlSock *nl.NetlinkSocket, nsPath string) {
// With the new version of the netlink library the deserialize function makes
// requests about the interface of the netlink message. This can succeed only
// if this go routine is in the target namespace. For this reason following we
// lock the thread on that namespace
runtime.LockOSThread()
defer runtime.UnlockOSThread()
newNs, err := netns.GetFromPath(nsPath)
if err != nil {
logrus.WithError(err).Errorf("failed to get the namespace %s", nsPath)
return
}
defer newNs.Close()
if err = netns.Set(newNs); err != nil {
logrus.WithError(err).Errorf("failed to enter the namespace %s", nsPath)
return
}
for {
msgs, err := nlSock.Receive()
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion drivers/overlay/overlay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package overlay

import (
"context"
"fmt"
"net"
"os"
"syscall"
"testing"
"time"
Expand Down Expand Up @@ -158,7 +160,7 @@ func TestNetlinkSocket(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
go func() {
n.watchMiss(nlSock)
n.watchMiss(nlSock, fmt.Sprintf("/proc/%d/task/%d/ns/net", os.Getpid(), syscall.Gettid()))
ch <- nil
}()
time.Sleep(5 * time.Second)
Expand Down