浏览代码

libnetwork: stop caching global netlink handle

The global netlink handle ns.NlHandle() is indirectly cached for the
life of the process by the netutils.CheckRouteOverlaps() function. This
caching behaviour is a problem for the libnetwork unit tests as the
global netlink handle changes every time testutils.SetupTestOSContext()
is called, i.e. at the start of nearly every test case. Route overlaps
can be checked for in the wrong network namespace, causing spurious test
failures e.g. when running the same test twice in a row with -count=2.
Stop the netlink handle from being cached by shadowing the package-scope
variable with a function-scoped one.

Signed-off-by: Cory Snider <csnider@mirantis.com>
Cory Snider 2 年之前
父节点
当前提交
1b64f2e28b
共有 1 个文件被更改,包括 1 次插入0 次删除
  1. 1 0
      libnetwork/netutils/utils_linux.go

+ 1 - 0
libnetwork/netutils/utils_linux.go

@@ -24,6 +24,7 @@ var (
 
 
 // CheckRouteOverlaps checks whether the passed network overlaps with any existing routes
 // CheckRouteOverlaps checks whether the passed network overlaps with any existing routes
 func CheckRouteOverlaps(toCheck *net.IPNet) error {
 func CheckRouteOverlaps(toCheck *net.IPNet) error {
+	networkGetRoutesFct := networkGetRoutesFct
 	if networkGetRoutesFct == nil {
 	if networkGetRoutesFct == nil {
 		networkGetRoutesFct = ns.NlHandle().RouteList
 		networkGetRoutesFct = ns.NlHandle().RouteList
 	}
 	}