v2rayA/v2rayA · error

tinytun route script (%s): failed to chmod temp file: %w

Error message

tinytun route script (%s): failed to chmod temp file: %w

What it means

This wraps os.Chmod failing when restricting the just-created temp script file to 0600 (non-Windows only) before writing content. The library throws it because the script must be private to avoid executing user-writable content from a world-readable/writable temp file.

Source

Thrown at service/kernel/v2ray/tinytun_enabled.go:751

	binPath := si.bin
	if !filepath.IsAbs(binPath) {
		if resolved, err := exec.LookPath(binPath); err == nil {
			binPath = resolved
		}
	}

	// Write script to a temp file with restricted permissions.
	tmpFile, err := os.CreateTemp("", "tinytun_*"+si.ext)
	if err != nil {
		return fmt.Errorf("tinytun route script (%s): failed to create temp file: %w", stage, err)
	}
	defer os.Remove(tmpFile.Name())

	// Restrict permissions immediately after creation (before writing content).
	if runtime.GOOS != "windows" {
		if err = os.Chmod(tmpFile.Name(), 0600); err != nil {
			tmpFile.Close()
			return fmt.Errorf("tinytun route script (%s): failed to chmod temp file: %w", stage, err)
		}
	}

	if _, err = tmpFile.WriteString(script); err != nil {
		tmpFile.Close()
		return fmt.Errorf("tinytun route script (%s): failed to write temp file: %w", stage, err)
	}
	tmpFile.Close()

	// Make the file executable on non-Windows systems.
	if runtime.GOOS != "windows" {
		if err = os.Chmod(tmpFile.Name(), 0700); err != nil {
			return fmt.Errorf("tinytun route script (%s): failed to chmod temp file executable: %w", stage, err)
		}
	}

	// Build command arguments.
	var args []string

View on GitHub (pinned to 71e5442fc5)

Solutions

  1. Point TMPDIR at a local filesystem that supports permission bits (e.g. /tmp on ext4).
  2. Check the wrapped OS error to confirm the filesystem limitation and relocate the temp dir.
  3. Re-run; transient races with temp-file cleaners usually resolve on retry.
Defensive patterns

Strategy: validation

Validate before calling

probe, err := os.CreateTemp(os.TempDir(), "perm_probe*")
if err == nil {
    if err2 := probe.Chmod(0600); err2 != nil {
        return fmt.Errorf("temp fs does not support chmod: %w", err2)
    }
    probe.Close(); os.Remove(probe.Name())
}

Try / catch

if err := runTinyTunScript(stage, script); err != nil {
    if strings.Contains(err.Error(), "failed to chmod temp file") {
        log.Warnf("temp filesystem lacks permission support: %v", err)
    }
    return err
}

Prevention

When it happens

Trigger: os.Chmod(tmpFile.Name(), 0600) at tinytun_enabled.go:751 returns an error right after CreateTemp succeeded — rare, but possible with unusual filesystems (e.g. some FUSE/NFS/vfat mounts) or concurrent removal of the temp file.

Common situations: Temp dir on a filesystem that does not support chmod (FAT/exFAT USB mounts, certain network mounts); TMPDIR on an overlay with odd ACLs; external cleanup racing the file.

Related errors


AI-assisted analysis of v2rayA/v2rayA@71e5442fc5 (2026-09-05). Data as JSON: /api/errors/406bb96a8677c76d. Report an issue: GitHub.