JuliusBrussee/caveman · error

native runtime listen

Error message

native runtime listen: %w

What it means

After clearing stale socket state, ServeUnix calls net.Listen("unix", path) to bind the socket. Any bind failure is wrapped as "native runtime listen". Common causes are the path being in use by a live listener or permission problems on the directory.

Solutions

  1. Stop the other process bound to the socket (pgrep/lsof) before starting the runtime
  2. Use a unique socket path per instance or per user
  3. Shorten the path so it fits the 108-byte unix socket limit

Example fix

// before
ServeUnix(ctx, "/tmp/a/very/long/path/exceeding/limits/nativeruntime.sock", rt)
// after
ServeUnix(ctx, "/tmp/nativeruntime.sock", rt)
Defensive patterns

Strategy: retry

Validate before calling

if conn, err := net.DialTimeout("unix", socketPath, 50*time.Millisecond); err == nil {
	conn.Close()
	return errors.New("runtime socket already active")
}

Try / catch

err := nativeruntime.ServeUnix(ctx, path, rt)
if err != nil {
	if strings.Contains(err.Error(), "listen") {
		// wait for the holder to exit, then retry once
		time.Sleep(500 * time.Millisecond)
		return nativeruntime.ServeUnix(ctx, path, rt)
	}
	return err
}

Prevention

When it happens

Trigger: net.Listen("unix", path) errors: another live process already holds the socket path (address in use), the directory is not writable, or the path exceeds the unix socket length limit.

Common situations: Two runtime instances launched simultaneously; leftover socket from a hung process that still answers probes; running in a sandbox with a restricted socket directory.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/44058c79dbd7cd92. Report an issue: GitHub.

Appendix: source

Thrown at proxy/internal/nativeruntime/server_unix.go:56

	}
	if err := os.Chmod(filepath.Dir(path), 0o700); err != nil {
		return fmt.Errorf("native runtime chmod dir: %w", err)
	}
	if _, err := os.Stat(path); err == nil {
		conn, dialErr := net.DialTimeout("unix", path, 50*time.Millisecond)
		if dialErr == nil {
			_ = conn.Close()
			return errors.New("native runtime: socket already active")
		}
		if err := os.Remove(path); err != nil {
			return fmt.Errorf("native runtime remove stale socket: %w", err)
		}
	} else if !os.IsNotExist(err) {
		return fmt.Errorf("native runtime inspect socket: %w", err)
	}
	listener, err := net.Listen("unix", path)
	if err != nil {
		return fmt.Errorf("native runtime listen: %w", err)
	}
	defer listener.Close()
	defer os.Remove(path)
	if err := os.Chmod(path, 0o600); err != nil {
		return fmt.Errorf("native runtime chmod socket: %w", err)
	}
	go func() {
		<-ctx.Done()
		_ = listener.Close()
	}()
	for {
		conn, err := listener.Accept()
		if err != nil {
			if ctx.Err() != nil {
				return nil
			}
			return fmt.Errorf("native runtime accept: %w", err)
		}

View on GitHub (pinned to 3ee70a1026)