Skip to content

Commit f459afb

Browse files
committed
Set a timeout on the netlink handle sockets
Signed-off-by: Alessandro Boch <[email protected]>
1 parent 30c32df commit f459afb

4 files changed

Lines changed: 28 additions & 0 deletions

File tree

drivers/overlay/ov_network.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@ func populateVNITbl() {
320320
}
321321
defer nlh.Delete()
322322

323+
err = nlh.SetSocketTimeout(soTimeout)
324+
if err != nil {
325+
logrus.Warnf("Failed to set the timeout on the netlink handle sockets for vni table population: %v", err)
326+
}
327+
323328
links, err := nlh.LinkList()
324329
if err != nil {
325330
logrus.Errorf("Failed to list interfaces during vni population for ns %s: %v", path, err)

drivers/overlay/ov_utils.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"github.com/vishvananda/netns"
1414
)
1515

16+
var soTimeout = ns.NetlinkSocketsTimeout
17+
1618
func validateID(nid, eid string) error {
1719
if nid == "" {
1820
return fmt.Errorf("invalid network id")
@@ -134,6 +136,10 @@ func deleteVxlanByVNI(path string, vni uint32) error {
134136
return fmt.Errorf("failed to get netlink handle for ns %s: %v", path, err)
135137
}
136138
defer nlh.Delete()
139+
err = nlh.SetSocketTimeout(soTimeout)
140+
if err != nil {
141+
logrus.Warnf("Failed to set the timeout on the netlink handle sockets for vxlan deletion: %v", err)
142+
}
137143
}
138144

139145
links, err := nlh.LinkList()

ns/init_linux.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88
"sync"
99
"syscall"
10+
"time"
1011

1112
"github.com/Sirupsen/logrus"
1213
"github.com/vishvananda/netlink"
@@ -17,6 +18,8 @@ var (
1718
initNs netns.NsHandle
1819
initNl *netlink.Handle
1920
initOnce sync.Once
21+
// NetlinkSocketsTimeout represents the default timeout duration for the sockets
22+
NetlinkSocketsTimeout = 3 * time.Second
2023
)
2124

2225
// Init initializes a new network namespace
@@ -30,6 +33,10 @@ func Init() {
3033
if err != nil {
3134
logrus.Errorf("could not create netlink handle on initial namespace: %v", err)
3235
}
36+
err = initNl.SetSocketTimeout(NetlinkSocketsTimeout)
37+
if err != nil {
38+
logrus.Warnf("Failed to set the timeout on the default netlink handle sockets: %v", err)
39+
}
3340
}
3441

3542
// SetNamespace sets the initial namespace handler

osl/namespace_linux.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ func NewSandbox(key string, osCreate, isRestore bool) (Sandbox, error) {
211211
return nil, fmt.Errorf("failed to create a netlink handle: %v", err)
212212
}
213213

214+
err = n.nlHandle.SetSocketTimeout(ns.NetlinkSocketsTimeout)
215+
if err != nil {
216+
logrus.Warnf("Failed to set the timeout on the sandbox netlink handle sockets: %v", err)
217+
}
218+
214219
if err = n.loopbackUp(); err != nil {
215220
n.nlHandle.Delete()
216221
return nil, err
@@ -253,6 +258,11 @@ func GetSandboxForExternalKey(basePath string, key string) (Sandbox, error) {
253258
return nil, fmt.Errorf("failed to create a netlink handle: %v", err)
254259
}
255260

261+
err = n.nlHandle.SetSocketTimeout(ns.NetlinkSocketsTimeout)
262+
if err != nil {
263+
logrus.Warnf("Failed to set the timeout on the sandbox netlink handle sockets: %v", err)
264+
}
265+
256266
if err = n.loopbackUp(); err != nil {
257267
n.nlHandle.Delete()
258268
return nil, err

0 commit comments

Comments
 (0)