Skip to content

Commit 65e0999

Browse files
author
Flavio Crisciani
committed
Fix leak of watchMiss goroutine
The netlink socket that was used to monitor the L2 miss was never being closed. The watchMiss goroutine spawned was never returning. This was causing goroutine leak in case of createNetwork/destroyNetwork Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
1 parent eed0fe8 commit 65e0999

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

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()

0 commit comments

Comments
 (0)