Skip to content

Commit

Permalink
Merge pull request #1786 from fcrisciani/netlink_leak
Browse files Browse the repository at this point in the history
Fix leak of watchMiss goroutine
  • Loading branch information
mavenugo authored Jun 6, 2017
2 parents 0bce3e1 + c2d86ca commit 7ec0ce6
Show file tree
Hide file tree
Showing 17 changed files with 877 additions and 56 deletions.
21 changes: 21 additions & 0 deletions drivers/overlay/ov_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type network struct {
dbIndex uint64
dbExists bool
sbox osl.Sandbox
nlSocket *nl.NetlinkSocket
endpoints endpointTable
driver *driver
joinCnt int
Expand Down Expand Up @@ -345,6 +346,12 @@ func (n *network) destroySandbox() {
}
}

// Close the netlink socket, this will also release the watchMiss goroutine that is using it
if n.nlSocket != nil {
n.nlSocket.Close()
n.nlSocket = nil
}

n.sbox.Destroy()
n.sbox = nil
}
Expand Down Expand Up @@ -685,6 +692,7 @@ func (n *network) initSandbox(restore bool) error {
sbox.InvokeFunc(func() {
nlSock, err = nl.Subscribe(syscall.NETLINK_ROUTE, syscall.RTNLGRP_NEIGH)
})
n.setNetlinkSocket(nlSock)

if err == nil {
go n.watchMiss(nlSock)
Expand All @@ -700,6 +708,13 @@ func (n *network) watchMiss(nlSock *nl.NetlinkSocket) {
for {
msgs, err := nlSock.Receive()
if err != nil {
n.Lock()
nlFd := nlSock.GetFd()
n.Unlock()
if nlFd == -1 {
// The netlink socket got closed, simply exit to not leak this goroutine
return
}
logrus.Errorf("Failed to receive from netlink: %v ", err)
continue
}
Expand Down Expand Up @@ -816,6 +831,12 @@ func (n *network) setSandbox(sbox osl.Sandbox) {
n.Unlock()
}

func (n *network) setNetlinkSocket(nlSk *nl.NetlinkSocket) {
n.Lock()
n.nlSocket = nlSk
n.Unlock()
}

func (n *network) vxlanID(s *subnet) uint32 {
n.Lock()
defer n.Unlock()
Expand Down
14 changes: 7 additions & 7 deletions vendor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ github.com/docker/libkv 1d8431073ae03cdaedb198a89722f3aab6d418ef

github.com/godbus/dbus 5f6efc7ef2759c81b7ba876593971bfce311eab3
github.com/gogo/protobuf 8d70fb3182befc465c4a1eac8ad4d38ff49778e2
github.com/golang/protobuf/proto f7137ae6b19afbfd61a94b746fda3b3fe0491874
github.com/golang/protobuf f7137ae6b19afbfd61a94b746fda3b3fe0491874
github.com/gorilla/context 215affda49addc4c8ef7e2534915df2c8c35c6cd
github.com/gorilla/mux 8096f47503459bcc74d1f4c487b7e6e42e5746b5
github.com/hashicorp/consul/api 954aec66231b79c161a4122b023fbcad13047f79
github.com/hashicorp/go-msgpack/codec 71c2886f5a673a35f909803f38ece5810165097b
github.com/hashicorp/consul 954aec66231b79c161a4122b023fbcad13047f79
github.com/hashicorp/go-msgpack 71c2886f5a673a35f909803f38ece5810165097b
github.com/hashicorp/go-multierror 2167c8ec40776024589f483a6b836489e47e1049
github.com/hashicorp/memberlist v0.1.0
github.com/sean-/seed e2103e2c35297fb7e17febb81e49b312087a2372
github.com/hashicorp/go-sockaddr acd314c5781ea706c710d9ea70069fd2e110d61d
github.com/hashicorp/serf 598c54895cc5a7b1a24a398d635e8c0ea0959870
github.com/mattn/go-shellwords 525bedee691b5a8df547cb5cf9f86b7fb1883e24
github.com/miekg/dns d27455715200c7d3e321a1e5cadb27c9ee0b0f02
github.com/opencontainers/runc/libcontainer ba1568de399395774ad84c2ace65937814c542ed
github.com/samuel/go-zookeeper/zk d0e0d8e11f318e000a8cc434616d69e329edc374
github.com/opencontainers/runc ba1568de399395774ad84c2ace65937814c542ed
github.com/samuel/go-zookeeper d0e0d8e11f318e000a8cc434616d69e329edc374
github.com/seccomp/libseccomp-golang 1b506fc7c24eec5a3693cdcbed40d9c226cfc6a1
github.com/stretchr/testify dab07ac62d4905d3e48d17dc549c684ac3b7c15a
github.com/syndtr/gocapability/capability 2c00daeb6c3b45114c80ac44119e7b8801fdd852
github.com/syndtr/gocapability 2c00daeb6c3b45114c80ac44119e7b8801fdd852
github.com/ugorji/go f1f1a805ed361a0e078bb537e4ea78cd37dcf065
github.com/vishvananda/netlink 1e86b2bee5b6a7d377e4c02bb7f98209d6a7297c
github.com/vishvananda/netlink bd6d5de5ccef2d66b0a26177928d0d8895d7f969
github.com/vishvananda/netns 604eaf189ee867d8c147fafc28def2394e878d25
golang.org/x/net c427ad74c6d7a814201695e9ffde0c5d400a7674
golang.org/x/sys 8f0908ab3b2457e2e15403d3697c9ef5cb4b57a9
Expand Down
12 changes: 7 additions & 5 deletions vendor/github.com/vishvananda/netlink/addr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion vendor/github.com/vishvananda/netlink/addr_linux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 9 additions & 13 deletions vendor/github.com/vishvananda/netlink/filter_linux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

167 changes: 167 additions & 0 deletions vendor/github.com/vishvananda/netlink/genetlink_linux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions vendor/github.com/vishvananda/netlink/genetlink_unspecified.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7ec0ce6

Please sign in to comment.