Skip to content
Open
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
9 changes: 9 additions & 0 deletions internal/vm/libkrun/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,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 macOS 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 {
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition checks if length is >= 104, but since the 104-character limit includes the null terminator (\0), the check should be > 103 or >= 104 with the actual path plus null terminator. The current check may reject valid 103-character paths. Consider changing to len(socketPath) > 103 to allow exactly 103 characters of actual path data.

Suggested change
if runtime.GOOS == "darwin" && len(socketPath) >= 104 {
if runtime.GOOS == "darwin" && len(socketPath) > 103 {

Copilot uses AI. Check for mistakes.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think copilot got confused by your comment:

is limited to 104 characters (including \0).

The limit is 104 bytes (so 103 chars + NUL byte), so the code is correct.

return fmt.Errorf("socket path is too long: %s", socketPath)
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message should provide actionable guidance. Consider enhancing it to explain the limitation and suggest a solution, such as: socket path exceeds macOS limit of 103 characters (%d): %s. Consider using a shorter state directory path or avoiding symlinked directories in /tmp

Suggested change
return fmt.Errorf("socket path is too long: %s", socketPath)
return fmt.Errorf("socket path exceeds macOS limit of 103 characters (%d): %s. Consider using a shorter state directory path or avoiding symlinked directories in /tmp", len(socketPath), socketPath)

Copilot uses AI. Check for mistakes.
}

if err := v.vmc.AddVSockPort(1025, socketPath); err != nil {
return fmt.Errorf("failed to add vsock port: %w", err)
}
Expand Down
Loading