-
Notifications
You must be signed in to change notification settings - Fork 806
Description
Hi,
Noticed that lots of downstream projects perform netlink operations with netlink.XXX API directly, which in the background uses the default pkg handle pkgHandle.
While it's the most intuitive and straight-forward way to use this package (for most scenarios), and works wonderfully most of the time, there are still probabilities of failures (hanging, specifically) due to socket timeout option not set for pkgHandle, such as cases in popular projects Calico (issue) and Cilium (issue).
So I'm wondering if we could improve it by allowing users to set socket timeout for the default handle. Such as the following draft:
diff --git a/handle_linux.go b/handle_linux.go
index 26887b7..e536310 100644
--- a/handle_linux.go
+++ b/handle_linux.go
@@ -10,7 +10,8 @@ import (
)
// Empty handle used by the netlink package methods
-var pkgHandle = &Handle{}
+var pkgHandle *Handle = nil
+var socketTimeout = 5 * time.Minute
+func init() {
+ h, err := NewHandle()
+ if err != nil {
+ panic("Create default pkg handle failed")
+ }
+
+ pkgHandle = h
+}
+
+func SetSocketTimeout(t time.Duration) error {
+ if pkgHandle == nil {
+ return fmt.Errorf("Default pkg handle not initialized")
+ }
+
+ socketTimeout = t
+ return pkgHandle.SetSocketTimeout(socketTimeout)
+}
+
+func GetSocketTimeout() (time.Duration, error) {
+ if pkgHandle == nil {
+ return 0, fmt.Errorf("Default pkg handle not initialized")
+ }
+
+ return socketTimeout, nil
+}
With this option, users no longer need to refactor their existing code by initializing their own pkg handles, which will save much effort for them.
Thanks!