mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
SetupTestOSContextEx calls 'ns.Init' (which, outside tests, is protected by a sync.Once), and it's called again by the returned OSContext.Cleanup method. That overwrites the ns package's namespace and netlink handles (initNs and initNl) without closing them. Because SetupTestOSContextEx changes that shared state, it should not be used in parallel tests. So, rather than trying to close the handles in ns.Init if already open - un-export Init so it's always called via its sync.Once, and add a reset function for tests to use. Have SetupTestOSContextEx claim a mutex to avoid crashy surprises or hard to catch issues where the ns package isn't using the expected namespace if it is used in parallel tests. Signed-off-by: Rob Murray <rob.murray@docker.com>