Skip to content

Commit 90a42e0

Browse files
committed
Add retries to conntracker.ListEntries()
Signed-off-by: Daman Arora <[email protected]>
1 parent 2b3da7d commit 90a42e0

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

pkg/proxy/conntrack/cleanup.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ limitations under the License.
2020
package conntrack
2121

2222
import (
23+
"errors"
2324
"time"
2425

2526
"github.com/vishvananda/netlink"
@@ -43,8 +44,12 @@ func CleanStaleEntries(ct Interface, ipFamily v1.IPFamily,
4344

4445
entries, err := ct.ListEntries(ipFamilyMap[ipFamily])
4546
if err != nil {
46-
klog.ErrorS(err, "Failed to list conntrack entries")
47-
return
47+
if errors.Is(err, unix.EINTR) {
48+
klog.V(2).ErrorS(err, "received a partial result, continuing to clean with partial result")
49+
} else {
50+
klog.ErrorS(err, "Failed to list conntrack entries")
51+
return
52+
}
4853
}
4954

5055
// serviceIPEndpointIPs maps service IPs (ClusterIP, LoadBalancerIPs and ExternalIPs)

pkg/proxy/conntrack/conntrack.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import (
2424

2525
"github.com/vishvananda/netlink"
2626

27+
"k8s.io/client-go/util/retry"
2728
"k8s.io/klog/v2"
29+
"k8s.io/kubernetes/pkg/proxy/util"
2830
)
2931

3032
// Interface for dealing with conntrack
@@ -57,8 +59,12 @@ func newConntracker(handler netlinkHandler) Interface {
5759
}
5860

5961
// ListEntries list all conntrack entries for connections of the given IP family.
60-
func (ct *conntracker) ListEntries(ipFamily uint8) ([]*netlink.ConntrackFlow, error) {
61-
return ct.handler.ConntrackTableList(netlink.ConntrackTable, netlink.InetFamily(ipFamily))
62+
func (ct *conntracker) ListEntries(ipFamily uint8) (entries []*netlink.ConntrackFlow, err error) {
63+
err = retry.OnError(util.MaxAttemptsEINTR, util.ShouldRetryOnEINTR, func() error {
64+
entries, err = ct.handler.ConntrackTableList(netlink.ConntrackTable, netlink.InetFamily(ipFamily))
65+
return err
66+
})
67+
return entries, err
6268
}
6369

6470
// ClearEntries deletes conntrack entries for connections of the given IP family,

pkg/proxy/util/utils_linux.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//go:build linux
2+
// +build linux
3+
4+
/*
5+
Copyright 2025 The Kubernetes Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
*/
19+
20+
package util
21+
22+
import (
23+
"errors"
24+
25+
"golang.org/x/sys/unix"
26+
27+
"k8s.io/apimachinery/pkg/util/wait"
28+
)
29+
30+
var MaxAttemptsEINTR = wait.Backoff{Steps: 5}
31+
var ShouldRetryOnEINTR = func(err error) bool { return errors.Is(err, unix.EINTR) }

0 commit comments

Comments
 (0)