{"record":{"id":"e5417a252d91aa70","repo":"hashicorp/nomad","slug":"failed-creating-temporary-directory-for-the-stated","errorCode":null,"errorMessage":"failed creating temporary directory for the StateDir: %v","messagePattern":"failed creating temporary directory for the StateDir: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/client.go","lineNumber":694,"sourceCode":"func (c *Client) Ready() <-chan struct{} {\n\treturn c.serversContactedCh\n}\n\n// init is used to initialize the client and perform any setup\n// needed before we begin starting its various components.\nfunc (c *Client) init() error {\n\t// Ensure the state dir exists if we have one\n\tconf := c.GetConfig()\n\tif conf.StateDir != \"\" {\n\t\tif err := os.MkdirAll(conf.StateDir, 0700); err != nil {\n\t\t\treturn fmt.Errorf(\"failed creating state dir: %s\", err)\n\t\t}\n\n\t} else {\n\t\t// Otherwise make a temp directory to use.\n\t\tp, err := os.MkdirTemp(\"\", \"NomadClient\")\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed creating temporary directory for the StateDir: %v\", err)\n\t\t}\n\n\t\tp, err = filepath.EvalSymlinks(p)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to find temporary directory for the StateDir: %v\", err)\n\t\t}\n\n\t\tconf = c.UpdateConfig(func(c *config.Config) {\n\t\t\tc.StateDir = p\n\t\t})\n\t}\n\tc.logger.Info(\"using state directory\", \"state_dir\", conf.StateDir)\n\n\t// Open the state database\n\tdb, err := conf.StateDBFactory(c.logger, conf.StateDir)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to open state database: %v\", err)\n\t}","sourceCodeStart":676,"sourceCodeEnd":712,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/client.go#L676-L712","documentation":"When no state_dir is configured, Client.init() creates a temporary directory via os.MkdirTemp(\"\", \"NomadClient\") for the state. If the OS temp-dir creation fails (usually TMPDIR problems or no writable temp location), this error is returned and blocks client startup.","triggerScenarios":"os.MkdirTemp fails because $TMPDIR points to a non-existent or non-writable path, the temp filesystem is full, or hard sandboxing (seccomp/SELinux) blocks mkdir in /tmp.","commonSituations":"Systemd unit with PrivateTmp plus a misconfigured tmpfs; TMPDIR set to a deleted or read-only path in the agent's environment; /tmp filled to capacity on small instances.","solutions":["Fix or unset TMPDIR in the Nomad agent's environment so /tmp (or the target) is writable.","Check /tmp (or $TMPDIR) exists, is writable by the nomad user, and has free space (df -h /tmp).","Explicitly set client { state_dir } to a writable path to bypass temp-dir creation entirely.","Check SELinux/seccomp policies that may deny mkdir for the nomad process in the temp location."],"exampleFix":"// before\nEnvironment=TMPDIR=/mnt/deleted-tmp  (systemd unit)\n# after\nEnvironment=TMPDIR=/var/tmp\n# or bypass entirely:\nclient { state_dir = \"/var/lib/nomad/state\" }","handlingStrategy":"validation","validationCode":"// verify a usable temp location before starting a client without state_dir\nif os.Getenv(\"TMPDIR\") != \"\" {\n    if fi, err := os.Stat(os.Getenv(\"TMPDIR\")); err != nil || !fi.IsDir() {\n        return fmt.Errorf(\"TMPDIR %q invalid\", os.Getenv(\"TMPDIR\"))\n    }\n} else if err := checkWritable(\"/tmp\"); err != nil {\n    return fmt.Errorf(\"/tmp not writable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set an explicit state_dir in production so temp-dir creation is never needed","Keep /tmp on a real writable filesystem with free space; watch tmpfs usage","Check TMPDIR in the agent's actual runtime environment (systemd, containers)","Review PrivateTmp/SELinux settings that sandbox temp dirs for the Nomad service"],"tags":["filesystem","temp-dir","initialization"],"backgroundTag":"directory-creation-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}