Skip to content

Commit

Permalink
release netlink socket when stop monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
PixelPixel00 committed Sep 18, 2024
1 parent 64b295a commit 7c1288d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/daemon/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,15 @@ func (c *CtrlHub) handleLocalNetworkDeviceEvent() error {
go func() {
for {
linkCh := make(chan netlink.LinkUpdate, LinkUpdateChainSize)
doneCh := make(chan struct{})
exitCh := make(chan struct{})

errorCallback := func(err error) {
c.logger.Error(err, "subscribe netlink link event exit with error")
close(exitCh)
}

if err := netlink.LinkSubscribeWithOptions(linkCh, nil, netlink.LinkSubscribeOptions{
if err := netlink.LinkSubscribeWithOptions(linkCh, doneCh, netlink.LinkSubscribeOptions{
Namespace: &hostNetNs,
ErrorCallback: errorCallback,
}); err != nil {
Expand All @@ -277,6 +278,7 @@ func (c *CtrlHub) handleLocalNetworkDeviceEvent() error {
c.ipInstanceTriggerSourceForHostLink.Trigger()
}
case <-exitCh:
close(doneCh)
break linkLoop
}
}
Expand All @@ -286,14 +288,15 @@ func (c *CtrlHub) handleLocalNetworkDeviceEvent() error {
go func() {
for {
addrCh := make(chan netlink.AddrUpdate, AddrUpdateChainSize)
doneCh := make(chan struct{})
exitCh := make(chan struct{})

errorCallback := func(err error) {
c.logger.Error(err, "subscribe netlink addr event exit with error")
close(exitCh)
}

if err := netlink.AddrSubscribeWithOptions(addrCh, nil, netlink.AddrSubscribeOptions{
if err := netlink.AddrSubscribeWithOptions(addrCh, doneCh, netlink.AddrSubscribeOptions{
Namespace: &hostNetNs,
ErrorCallback: errorCallback,
}); err != nil {
Expand All @@ -319,6 +322,7 @@ func (c *CtrlHub) handleLocalNetworkDeviceEvent() error {
c.nodeInfoTriggerSourceForHostAddr.Trigger()
}
case <-exitCh:
close(doneCh)
break addrLoop
}
}
Expand Down Expand Up @@ -426,14 +430,15 @@ func (c *CtrlHub) handleVxlanInterfaceNeighEvent() error {
}

neighCh := make(chan netlink.NeighUpdate, NeighUpdateChanSize)
doneCh := make(chan struct{})
exitCh := make(chan struct{})

errorCallback := func(err error) {
c.logger.Error(err, "subscribe netlink neigh event exit with error")
close(exitCh)
}

if err := netlink.NeighSubscribeWithOptions(neighCh, nil, netlink.NeighSubscribeOptions{
if err := netlink.NeighSubscribeWithOptions(neighCh, doneCh, netlink.NeighSubscribeOptions{
Namespace: &hostNetNs,
ErrorCallback: errorCallback,
}); err != nil {
Expand Down Expand Up @@ -466,6 +471,7 @@ func (c *CtrlHub) handleVxlanInterfaceNeighEvent() error {
c.logger.Error(err, "failed to clear vxlan expired neigh caches")
}
case <-exitCh:
close(doneCh)
break neighLoop
}
}
Expand Down

0 comments on commit 7c1288d

Please sign in to comment.