Browse code

fix(libnetwork): nil pointer will cause panic

make panic info more useful

Signed-off-by: jokemanfire <hu.dingyang@zte.com.cn>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

jokemanfire authored on 2025/11/12 10:39:08
Showing 1 changed files
... ...
@@ -2,6 +2,7 @@ package ns
2 2
 
3 3
 import (
4 4
 	"context"
5
+	"fmt"
5 6
 	"sync"
6 7
 	"syscall"
7 8
 	"testing"
... ...
@@ -30,7 +31,8 @@ func initHandles() {
30 30
 	}
31 31
 	initNl, err = nlwrap.NewHandle(getSupportedNlFamilies()...)
32 32
 	if err != nil {
33
-		log.G(context.TODO()).Errorf("could not create netlink handle on initial namespace: %v", err)
33
+		// Fail fast to keep the invariant: NlHandle must be a valid handle
34
+		panic(fmt.Errorf("could not create netlink handle on initial (host) namespace: %w", err))
34 35
 	}
35 36
 	err = initNl.SetSocketTimeout(NetlinkSocketsTimeout)
36 37
 	if err != nil {