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

release netlink socket when stop monitoring #424

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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
Loading