From 058eec4fd4895d9f7e91b9b603d902606715ae52 Mon Sep 17 00:00:00 2001 From: Albin Kerouanton Date: Wed, 28 Jan 2026 16:42:27 +0100 Subject: [PATCH] error out when run_vminitd.sock path length is too long UNIX socket path is limited to 104 characters (including \0) on macOS and 108 on Linux and Windows. To circumvent this limitation, vmInstance.Start() tries to compute the relative path to the run_vminitd.sock. However, if the bundle path points to a symlinked directory, this relative path may contain many double-dots and the full path, exceeding the limit. This is the case if containerd state dir is in /tmp (which is symlinked to /private/tmp on macOS). In that case, nothing fails explicitly. It appears as if the VM failed to start, whereas the log show that vminitd executed successfully. The only error logged is: Timeout while waiting for VM to start. Detect if the socket path is too long before trying to start the VM, and return an explicit error. Signed-off-by: Albin Kerouanton --- internal/vm/libkrun/instance.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/vm/libkrun/instance.go b/internal/vm/libkrun/instance.go index 3aa1ead..cfe3c1c 100644 --- a/internal/vm/libkrun/instance.go +++ b/internal/vm/libkrun/instance.go @@ -250,10 +250,19 @@ func (v *vmInstance) Start(ctx context.Context, opts ...vm.StartOpt) (err error) return fmt.Errorf("failed to get cwd: %w", err) } socketPath := filepath.Join(v.state, "run_vminitd.sock") + // Compute the relative socket path to avoid exceeding the max length on macOS. socketPath, err = filepath.Rel(cwd, socketPath) if err != nil { return fmt.Errorf("failed to get relative socket path: %w", err) } + // When the socket path exceeds max length, it appears as if the VM didn't + // start properly. There's no easy way to figure this out as the only log + // is: "Timeout while waiting for VM to start". Thus, return an error + // preventively here. + if (runtime.GOOS == "darwin" && len(socketPath) >= 104) || len(socketPath) >= 108 { + return fmt.Errorf("socket path is too long: %s", socketPath) + } + if err := v.vmc.AddVSockPort(1025, socketPath); err != nil { return fmt.Errorf("failed to add vsock port: %w", err) }