Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Enable remote docker tests #388

Conversation

denis-tingaikin
Copy link
Member

No description provided.

@denis-tingaikin denis-tingaikin force-pushed the enable-remote-tests branch 2 times, most recently from 0476a14 to 3048929 Compare November 10, 2021 16:20
Signed-off-by: denis-tingaikin <denis.tingajkin@xored.com>
@denis-tingaikin
Copy link
Member Author

@NikitaSkrynnik Could you continue this?

@edwarnicke
Copy link
Member

@NikitaSkrynnik A few (hopefully) helpful pointers.

Part of what is breaking is that I was sloppy about handling netns in newKernelVerifiableEndpoint and newKernelVerifiableClient.

rootNSHandle, err := netns.Get()
if err != nil {
panic(fmt.Sprintf("unable to get root netNs: %+v", err))
}
endpointNSName := fmt.Sprintf("nse-%s", randstr.Hex(4))
endpointNSHandle, err := netns.NewNamed(endpointNSName)
if err != nil {
panic(fmt.Sprintf("unable create netNs %s: %+v", endpointNSName, err))
}

calls netns.NewNamed(...) ... the problem is this switches the netns of the thread on which its called, and we don't switch it back correctly. The result is that some of the threads onto which goroutines may be scheduled are not on the root netns. This is what is causing the EADDRNOTAVAIL error when attempting to listen for a proxy.

The good news is, it can be fixed roughly by:

	rootNSHandle, err := netns.Get()
	if err != nil {
		panic(fmt.Sprintf("unable to get root netNs: %+v", err))
	}
	endpointNSName := fmt.Sprintf("nse-%s", randstr.Hex(4))
        runtime.LockOSThread()
        defer runtime.UnLockOSThread()
	endpointNSHandle, err := netns.NewNamed(endpointNSName)
	if err != nil {
		panic(fmt.Sprintf("unable create netNs %s: %+v", endpointNSName, err))
	}
        if err := netns.Set(rootNSHandle); err != nil { 
                // error handling 
        }
	go func(endpointNsName string,endpointNSHandle netns.NSHandle) {
		<-ctx.Done()
                 _ = endpointNSHandle.Close()
		_ = netns.DeleteNamed(endpointNsName)
	}(endpointNSName)

and something analogous for the newKernelVerifiableClient.

netns.Set(rootNSHandle) sets us back to the root netns.

runtime.LockOSThread() locks us to a single thread, so that all the statements in this function execute on that thread. This is important because we want to make sure we call netns.Set(rootNSHandle) on the same thread we called netns.NewNamed(...)

Questions?

@NikitaSkrynnik
Copy link
Contributor

@edwarnicke Ok, I understand it now. Thanks :)

@denis-tingaikin
Copy link
Member Author

Fixed in #410

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants