hashicorp/nomad · critical

failed to find temporary directory for the AllocDir: %v

Error message

failed to find temporary directory for the AllocDir: %v

What it means

Immediately after creating the temporary alloc dir, the client resolves it with filepath.EvalSymlinks to get the canonical path. If resolution fails (the path cannot be resolved through the filesystem), init aborts with this error.

Source

Thrown at client/client.go:754

			return fmt.Errorf("failed creating alloc mounts dir: %w", err)
		}
	}

	// Ensure the alloc dir exists if we are configured with a custom path.
	if conf.AllocDir != "" {
		if err := os.MkdirAll(conf.AllocDir, 0o711); err != nil {
			return fmt.Errorf("failed creating alloc dir: %w", err)
		}
	} else {
		// Otherwise make a temp directory to use.
		p, err := os.MkdirTemp("", "NomadClient")
		if err != nil {
			return fmt.Errorf("failed creating temporary directory for the AllocDir: %v", err)
		}

		p, err = filepath.EvalSymlinks(p)
		if err != nil {
			return fmt.Errorf("failed to find temporary directory for the AllocDir: %v", err)
		}

		// Change the permissions to have the execute bit
		if err := os.Chmod(p, 0o711); err != nil {
			return fmt.Errorf("failed to change directory permissions for the AllocDir: %v", err)
		}

		conf = c.UpdateConfig(func(c *config.Config) {
			c.AllocDir = p
			c.AllocMountsDir = p
		})
	}

	c.logger.Info("using alloc directory", "alloc_dir", conf.AllocDir)

	reserved := "<none>"
	if conf.Node != nil && conf.Node.ReservedResources != nil {
		// Node should always be non-nil due to initialization in the

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Inspect the wrapped OS error to identify which path component failed resolution and fix it (usually a broken TMPDIR symlink).
  2. Ensure TMPDIR points to a real directory path without broken symlink components.
  3. Set an explicit alloc_dir in client config to bypass temporary directory creation entirely.

Example fix

// before
sudo ln -sfn /mnt/removed-vol /var/tmp/nomadtmp; TMPDIR=/var/tmp/nomadtmp nomad agent -client
// after
rm /var/tmp/nomadtmp && mkdir -p /var/tmp/nomadtmp
# or
client { alloc_dir = "/var/lib/nomad/alloc" }
Defensive patterns

Strategy: validation

Validate before calling

tmp := os.TempDir()
resolved, err := filepath.EvalSymlinks(tmp)
if err != nil {
    return fmt.Errorf("TMPDIR %q cannot be resolved: %v", tmp, err)
}
_ = resolved

Try / catch

if err := clientInit(); err != nil {
    if strings.Contains(err.Error(), "failed to find temporary directory for the AllocDir") {
        // repair TMPDIR symlink chain or switch to explicit alloc_dir
    }
}

Prevention

When it happens

Trigger: client init without alloc_dir configured: os.MkdirTemp succeeds but filepath.EvalSymlinks(p) on the new NomadClient temp dir returns error.

Common situations: Temp root on symlinked/overlay filesystems where resolution races or fails, sandboxed environments (rare), or TMPDIR containing broken symlink components.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/3f37de3ce3cdd4d5. Report an issue: GitHub.