Skip to content

Commit

Permalink
Fix netlink leak (#9609)
Browse files Browse the repository at this point in the history
  • Loading branch information
sridhartigera authored Dec 18, 2024
1 parent 1e7b062 commit c68d79b
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions cni-plugin/internal/pkg/testutils/utils_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ func RunCNIPluginWithId(
return err
}

defer nlHandle.Close()
contVeth, err = nlHandle.LinkByName(ifName)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions cni-plugin/tests/calico_cni_k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ var _ = Describe("Kubernetes CNI tests", func() {
// Assert if the host side route is programmed correctly.
nlHandle, err := netlink.NewHandle(syscall.NETLINK_ROUTE)
Expect(err).ShouldNot(HaveOccurred())
defer nlHandle.Close()
hostRoutes, err := netlinkutils.RouteListRetryEINTR(nlHandle, hostVeth, syscall.AF_INET)
Expect(err).ShouldNot(HaveOccurred())
Expect(hostRoutes[0]).Should(Equal(netlink.Route{
Expand Down
1 change: 1 addition & 0 deletions cni-plugin/tests/calico_cni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ var _ = Describe("CalicoCni", func() {
// Assert if the host side route is programmed correctly.
nlHandle, err := netlink.NewHandle(syscall.NETLINK_ROUTE)
Expect(err).ShouldNot(HaveOccurred())
defer nlHandle.Close()
hostRoutes, err := netlinkutils.RouteListRetryEINTR(nlHandle, hostVeth, syscall.AF_INET)
Expect(err).ShouldNot(HaveOccurred())
Expect(hostRoutes[0]).Should(Equal(netlink.Route{
Expand Down
1 change: 1 addition & 0 deletions felix/dataplane/linux/int_dataplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,7 @@ func findHostMTU(matchRegex *regexp.Regexp) (int, error) {
return 0, err
}

defer nlHandle.Delete()
links, err := nlHandle.LinkList()
if err != nil {
log.WithError(err).Error("Failed to list interfaces. Unable to auto-detect MTU.")
Expand Down
1 change: 1 addition & 0 deletions felix/fv/etcd_restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ var _ = Context("etcd connection interruption", func() {
if err != nil {
return err
}
defer nlHandle.Close()
links, err := netlinkutils.LinkListRetryEINTR(nlHandle)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions felix/fv/ipip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ var _ = infrastructure.DatastoreDescribe("_BPF-SAFE_ IPIP topology before adding
if err != nil {
return err
}
defer nlHandle.Close()
links, err := netlinkutils.LinkListRetryEINTR(nlHandle)
if err != nil {
return err
Expand Down

0 comments on commit c68d79b

Please sign in to comment.