Skip to content

Commit 7ec0ce6

Browse files
authored
Merge pull request #1786 from fcrisciani/netlink_leak
Fix leak of watchMiss goroutine
2 parents 0bce3e1 + c2d86ca commit 7ec0ce6

17 files changed

Lines changed: 877 additions & 56 deletions

drivers/overlay/ov_network.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type network struct {
5858
dbIndex uint64
5959
dbExists bool
6060
sbox osl.Sandbox
61+
nlSocket *nl.NetlinkSocket
6162
endpoints endpointTable
6263
driver *driver
6364
joinCnt int
@@ -345,6 +346,12 @@ func (n *network) destroySandbox() {
345346
}
346347
}
347348

349+
// Close the netlink socket, this will also release the watchMiss goroutine that is using it
350+
if n.nlSocket != nil {
351+
n.nlSocket.Close()
352+
n.nlSocket = nil
353+
}
354+
348355
n.sbox.Destroy()
349356
n.sbox = nil
350357
}
@@ -685,6 +692,7 @@ func (n *network) initSandbox(restore bool) error {
685692
sbox.InvokeFunc(func() {
686693
nlSock, err = nl.Subscribe(syscall.NETLINK_ROUTE, syscall.RTNLGRP_NEIGH)
687694
})
695+
n.setNetlinkSocket(nlSock)
688696

689697
if err == nil {
690698
go n.watchMiss(nlSock)
@@ -700,6 +708,13 @@ func (n *network) watchMiss(nlSock *nl.NetlinkSocket) {
700708
for {
701709
msgs, err := nlSock.Receive()
702710
if err != nil {
711+
n.Lock()
712+
nlFd := nlSock.GetFd()
713+
n.Unlock()
714+
if nlFd == -1 {
715+
// The netlink socket got closed, simply exit to not leak this goroutine
716+
return
717+
}
703718
logrus.Errorf("Failed to receive from netlink: %v ", err)
704719
continue
705720
}
@@ -816,6 +831,12 @@ func (n *network) setSandbox(sbox osl.Sandbox) {
816831
n.Unlock()
817832
}
818833

834+
func (n *network) setNetlinkSocket(nlSk *nl.NetlinkSocket) {
835+
n.Lock()
836+
n.nlSocket = nlSk
837+
n.Unlock()
838+
}
839+
819840
func (n *network) vxlanID(s *subnet) uint32 {
820841
n.Lock()
821842
defer n.Unlock()

vendor.conf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@ github.com/docker/libkv 1d8431073ae03cdaedb198a89722f3aab6d418ef
1919

2020
github.com/godbus/dbus 5f6efc7ef2759c81b7ba876593971bfce311eab3
2121
github.com/gogo/protobuf 8d70fb3182befc465c4a1eac8ad4d38ff49778e2
22-
github.com/golang/protobuf/proto f7137ae6b19afbfd61a94b746fda3b3fe0491874
22+
github.com/golang/protobuf f7137ae6b19afbfd61a94b746fda3b3fe0491874
2323
github.com/gorilla/context 215affda49addc4c8ef7e2534915df2c8c35c6cd
2424
github.com/gorilla/mux 8096f47503459bcc74d1f4c487b7e6e42e5746b5
25-
github.com/hashicorp/consul/api 954aec66231b79c161a4122b023fbcad13047f79
26-
github.com/hashicorp/go-msgpack/codec 71c2886f5a673a35f909803f38ece5810165097b
25+
github.com/hashicorp/consul 954aec66231b79c161a4122b023fbcad13047f79
26+
github.com/hashicorp/go-msgpack 71c2886f5a673a35f909803f38ece5810165097b
2727
github.com/hashicorp/go-multierror 2167c8ec40776024589f483a6b836489e47e1049
2828
github.com/hashicorp/memberlist v0.1.0
2929
github.com/sean-/seed e2103e2c35297fb7e17febb81e49b312087a2372
3030
github.com/hashicorp/go-sockaddr acd314c5781ea706c710d9ea70069fd2e110d61d
3131
github.com/hashicorp/serf 598c54895cc5a7b1a24a398d635e8c0ea0959870
3232
github.com/mattn/go-shellwords 525bedee691b5a8df547cb5cf9f86b7fb1883e24
3333
github.com/miekg/dns d27455715200c7d3e321a1e5cadb27c9ee0b0f02
34-
github.com/opencontainers/runc/libcontainer ba1568de399395774ad84c2ace65937814c542ed
35-
github.com/samuel/go-zookeeper/zk d0e0d8e11f318e000a8cc434616d69e329edc374
34+
github.com/opencontainers/runc ba1568de399395774ad84c2ace65937814c542ed
35+
github.com/samuel/go-zookeeper d0e0d8e11f318e000a8cc434616d69e329edc374
3636
github.com/seccomp/libseccomp-golang 1b506fc7c24eec5a3693cdcbed40d9c226cfc6a1
3737
github.com/stretchr/testify dab07ac62d4905d3e48d17dc549c684ac3b7c15a
38-
github.com/syndtr/gocapability/capability 2c00daeb6c3b45114c80ac44119e7b8801fdd852
38+
github.com/syndtr/gocapability 2c00daeb6c3b45114c80ac44119e7b8801fdd852
3939
github.com/ugorji/go f1f1a805ed361a0e078bb537e4ea78cd37dcf065
40-
github.com/vishvananda/netlink 1e86b2bee5b6a7d377e4c02bb7f98209d6a7297c
40+
github.com/vishvananda/netlink bd6d5de5ccef2d66b0a26177928d0d8895d7f969
4141
github.com/vishvananda/netns 604eaf189ee867d8c147fafc28def2394e878d25
4242
golang.org/x/net c427ad74c6d7a814201695e9ffde0c5d400a7674
4343
golang.org/x/sys 8f0908ab3b2457e2e15403d3697c9ef5cb4b57a9

vendor/github.com/vishvananda/netlink/addr.go

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/vishvananda/netlink/addr_linux.go

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/vishvananda/netlink/filter_linux.go

Lines changed: 9 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/vishvananda/netlink/genetlink_linux.go

Lines changed: 167 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/vishvananda/netlink/genetlink_unspecified.go

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)