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

Windows: call runtime.LockOSThread in network-setup #8008

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/rancher-desktop/assets/scripts/wsl-init
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if [ $$ -ne "1" ]; then
# from WSL.
exec /usr/local/bin/network-setup --logfile "$NETWORK_SETUP_LOG" \
--vm-switch-path /usr/local/bin/vm-switch --vm-switch-logfile \
"$VM_SWITCH_LOG" --unshare-arg "${0}"
"$VM_SWITCH_LOG" ${RD_DEBUG:+-debug} --unshare-arg "${0}"
fi

# Mark directories that we will need to bind mount as shared mounts.
Expand Down
17 changes: 11 additions & 6 deletions pkg/rancher-desktop/backend/wsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1041,15 +1041,20 @@ export default class WSLBackend extends events.EventEmitter implements VMBackend

// The process should already be gone by this point, but make sure.
this.process?.kill('SIGTERM');
const env: Record<string, string> = {
...process.env,
WSLENV: `${ process.env.WSLENV }:DISTRO_DATA_DIRS:LOG_DIR/p:RD_DEBUG`,
DISTRO_DATA_DIRS: DISTRO_DATA_DIRS.join(':'),
LOG_DIR: paths.logs,
};

if (this.debug) {
env.RD_DEBUG = '1';
}
this.process = childProcess.spawn('wsl.exe',
['--distribution', INSTANCE_NAME, '--exec', '/usr/local/bin/wsl-init'],
{
env: {
...process.env,
WSLENV: `${ process.env.WSLENV }:DISTRO_DATA_DIRS:LOG_DIR/p`,
DISTRO_DATA_DIRS: DISTRO_DATA_DIRS.join(':'),
LOG_DIR: paths.logs,
},
env,
stdio: ['ignore', 'pipe', 'pipe'],
windowsHide: true,
});
Expand Down
14 changes: 10 additions & 4 deletions src/go/networking/cmd/network/setup_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"os/exec"
"os/signal"
"runtime"
"strconv"

"github.com/linuxkit/virtsock/pkg/vsock"
Expand Down Expand Up @@ -88,6 +89,11 @@ func main() {
}
logrus.Debugf("successful connection to host on CID: %v and Port: %d: connection: %+v", vsock.CIDHost, vsockDialPort, vsockConn)

// Ensure we stay on the same OS thread so that we don't switch namespaces
// accidentally.
runtime.LockOSThread()
defer runtime.UnlockOSThread()

originNS, err := netns.Get()
if err != nil {
logrus.Errorf("failed getting a handle to the current namespace: %v", err)
Expand Down Expand Up @@ -151,7 +157,7 @@ func main() {
logrus.Errorf("failed to close original NS, ignoring error: %v", err)
}

logrus.Trace("Network setup complete, waiting for vm-switch")
logrus.Debug("Network setup complete, waiting for vm-switch")

if err := vmSwitchCmd.Wait(); err != nil {
logrus.Errorf("vm-switch exited with error: %v", err)
Expand Down Expand Up @@ -250,7 +256,7 @@ func cleanupVethLink(originNS netns.NsHandle) {
func configureVethPair(vethName, ipAddr string) error {
veth, err := netlink.LinkByName(vethName)
if err != nil {
return err
return fmt.Errorf("failed to get link %s: %w", vethName, err)
}

vethIP := net.IPNet{
Expand All @@ -260,11 +266,11 @@ func configureVethPair(vethName, ipAddr string) error {

addr := &netlink.Addr{IPNet: &vethIP, Label: ""}
if err := netlink.AddrAdd(veth, addr); err != nil {
return err
return fmt.Errorf("failed to add addr %s to %s: %w", addr, vethName, err)
}

if err := netlink.LinkSetUp(veth); err != nil {
return err
return fmt.Errorf("failed to set up link %s: %w", vethName, err)
}
return nil
}
Expand Down
Loading