This reverts commit 94af1e5af201a87c651ef1a531bb19efdcd413e0.
The reason to revert this is, that TestCreateParallel is
continously failing and breaking the CI
Signed-off-by: Arko Dasgupta <arko.dasgupta@docker.com>
| ... | ... |
@@ -850,7 +850,6 @@ func parallelJoin(t *testing.T, rc libnetwork.Sandbox, ep libnetwork.Endpoint, t |
| 850 | 850 |
err = ep.Join(sb) |
| 851 | 851 |
|
| 852 | 852 |
runtime.LockOSThread() |
| 853 |
- defer runtime.UnlockOSThread() |
|
| 854 | 853 |
if err != nil {
|
| 855 | 854 |
if _, ok := err.(types.ForbiddenError); !ok {
|
| 856 | 855 |
t.Fatalf("thread %d: %v", thrNumber, err)
|
| ... | ... |
@@ -868,7 +867,6 @@ func parallelLeave(t *testing.T, rc libnetwork.Sandbox, ep libnetwork.Endpoint, |
| 868 | 868 |
|
| 869 | 869 |
err = ep.Leave(sb) |
| 870 | 870 |
runtime.LockOSThread() |
| 871 |
- defer runtime.UnlockOSThread() |
|
| 872 | 871 |
if err != nil {
|
| 873 | 872 |
if _, ok := err.(types.ForbiddenError); !ok {
|
| 874 | 873 |
t.Fatalf("thread %d: %v", thrNumber, err)
|
| ... | ... |
@@ -39,6 +39,19 @@ func Init() {
|
| 39 | 39 |
} |
| 40 | 40 |
} |
| 41 | 41 |
|
| 42 |
+// SetNamespace sets the initial namespace handler |
|
| 43 |
+func SetNamespace() error {
|
|
| 44 |
+ initOnce.Do(Init) |
|
| 45 |
+ if err := netns.Set(initNs); err != nil {
|
|
| 46 |
+ linkInfo, linkErr := getLink() |
|
| 47 |
+ if linkErr != nil {
|
|
| 48 |
+ linkInfo = linkErr.Error() |
|
| 49 |
+ } |
|
| 50 |
+ return fmt.Errorf("failed to set to initial namespace, %v, initns fd %d: %v", linkInfo, initNs, err)
|
|
| 51 |
+ } |
|
| 52 |
+ return nil |
|
| 53 |
+} |
|
| 54 |
+ |
|
| 42 | 55 |
// ParseHandlerInt transforms the namespace handler into an integer |
| 43 | 56 |
func ParseHandlerInt() int {
|
| 44 | 57 |
return int(getHandler()) |
| ... | ... |
@@ -424,10 +424,13 @@ func (n *networkNamespace) InvokeFunc(f func()) error {
|
| 424 | 424 |
// InitOSContext initializes OS context while configuring network resources |
| 425 | 425 |
func InitOSContext() func() {
|
| 426 | 426 |
runtime.LockOSThread() |
| 427 |
+ if err := ns.SetNamespace(); err != nil {
|
|
| 428 |
+ logrus.Error(err) |
|
| 429 |
+ } |
|
| 427 | 430 |
return runtime.UnlockOSThread |
| 428 | 431 |
} |
| 429 | 432 |
|
| 430 |
-func nsInvoke(path string, prefunc, postfunc func(int) error) error {
|
|
| 433 |
+func nsInvoke(path string, prefunc func(nsFD int) error, postfunc func(callerFD int) error) error {
|
|
| 431 | 434 |
defer InitOSContext()() |
| 432 | 435 |
|
| 433 | 436 |
newNs, err := netns.GetFromPath(path) |
| ... | ... |
@@ -442,17 +445,10 @@ func nsInvoke(path string, prefunc, postfunc func(int) error) error {
|
| 442 | 442 |
return fmt.Errorf("failed in prefunc: %v", err)
|
| 443 | 443 |
} |
| 444 | 444 |
|
| 445 |
- // save the current namespace (host namespace) |
|
| 446 |
- curNs, err := netns.Get() |
|
| 447 |
- if err != nil {
|
|
| 448 |
- return err |
|
| 449 |
- } |
|
| 450 |
- defer curNs.Close() |
|
| 451 | 445 |
if err = netns.Set(newNs); err != nil {
|
| 452 | 446 |
return err |
| 453 | 447 |
} |
| 454 |
- // will restore the previous namespace before unlocking the thread |
|
| 455 |
- defer netns.Set(curNs) |
|
| 448 |
+ defer ns.SetNamespace() |
|
| 456 | 449 |
|
| 457 | 450 |
// Invoked after the namespace switch. |
| 458 | 451 |
return postfunc(ns.ParseHandlerInt()) |
| ... | ... |
@@ -7,6 +7,7 @@ import ( |
| 7 | 7 |
"net" |
| 8 | 8 |
"os" |
| 9 | 9 |
"path/filepath" |
| 10 |
+ "runtime" |
|
| 10 | 11 |
"strings" |
| 11 | 12 |
"syscall" |
| 12 | 13 |
"testing" |
| ... | ... |
@@ -198,6 +199,7 @@ func TestDisableIPv6DAD(t *testing.T) {
|
| 198 | 198 |
if err != nil {
|
| 199 | 199 |
t.Fatalf("Failed to create a new sandbox: %v", err)
|
| 200 | 200 |
} |
| 201 |
+ runtime.LockOSThread() |
|
| 201 | 202 |
defer s.Destroy() |
| 202 | 203 |
|
| 203 | 204 |
n, ok := s.(*networkNamespace) |
| ... | ... |
@@ -251,6 +253,7 @@ func TestSetInterfaceIP(t *testing.T) {
|
| 251 | 251 |
if err != nil {
|
| 252 | 252 |
t.Fatalf("Failed to create a new sandbox: %v", err)
|
| 253 | 253 |
} |
| 254 |
+ runtime.LockOSThread() |
|
| 254 | 255 |
defer s.Destroy() |
| 255 | 256 |
|
| 256 | 257 |
n, ok := s.(*networkNamespace) |
| ... | ... |
@@ -326,6 +329,7 @@ func TestLiveRestore(t *testing.T) {
|
| 326 | 326 |
if err != nil {
|
| 327 | 327 |
t.Fatalf("Failed to create a new sandbox: %v", err)
|
| 328 | 328 |
} |
| 329 |
+ runtime.LockOSThread() |
|
| 329 | 330 |
defer s.Destroy() |
| 330 | 331 |
|
| 331 | 332 |
n, ok := s.(*networkNamespace) |
| ... | ... |
@@ -2,6 +2,7 @@ package osl |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"os" |
| 5 |
+ "runtime" |
|
| 5 | 6 |
"testing" |
| 6 | 7 |
|
| 7 | 8 |
"github.com/docker/docker/pkg/reexec" |
| ... | ... |
@@ -79,6 +80,7 @@ func TestSandboxCreateTwice(t *testing.T) {
|
| 79 | 79 |
if err != nil {
|
| 80 | 80 |
t.Fatalf("Failed to create a new sandbox: %v", err)
|
| 81 | 81 |
} |
| 82 |
+ runtime.LockOSThread() |
|
| 82 | 83 |
|
| 83 | 84 |
// Create another sandbox with the same key to see if we handle it |
| 84 | 85 |
// gracefully. |
| ... | ... |
@@ -86,6 +88,7 @@ func TestSandboxCreateTwice(t *testing.T) {
|
| 86 | 86 |
if err != nil {
|
| 87 | 87 |
t.Fatalf("Failed to create a new sandbox: %v", err)
|
| 88 | 88 |
} |
| 89 |
+ runtime.LockOSThread() |
|
| 89 | 90 |
|
| 90 | 91 |
err = s.Destroy() |
| 91 | 92 |
if err != nil {
|
| ... | ... |
@@ -127,6 +130,7 @@ func TestAddRemoveInterface(t *testing.T) {
|
| 127 | 127 |
if err != nil {
|
| 128 | 128 |
t.Fatalf("Failed to create a new sandbox: %v", err)
|
| 129 | 129 |
} |
| 130 |
+ runtime.LockOSThread() |
|
| 130 | 131 |
|
| 131 | 132 |
if s.Key() != key {
|
| 132 | 133 |
t.Fatalf("s.Key() returned %s. Expected %s", s.Key(), key)
|