{"record":{"id":"5096390a8c55b0db","repo":"hashicorp/nomad","slug":"error-creating-task-q-dir-w","errorCode":null,"errorMessage":"error creating task %q dir: %w","messagePattern":"error creating task %q dir: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/allocdir/alloc_dir.go","lineNumber":308,"sourceCode":"\tdataDir := filepath.Join(a.SharedDir, SharedDataDir)\n\tif fileInfo, err := os.Stat(otherDataDir); fileInfo != nil && err == nil {\n\t\tos.Remove(dataDir) // remove an empty data dir if it exists\n\t\tif err := os.Rename(otherDataDir, dataDir); err != nil {\n\t\t\treturn fmt.Errorf(\"error moving data dir: %w\", err)\n\t\t}\n\t}\n\n\t// Move the task directories\n\tfor _, task := range tasks {\n\t\totherTaskDir := filepath.Join(other.AllocDirPath(), task.Name)\n\t\totherTaskLocal := filepath.Join(otherTaskDir, TaskLocal)\n\n\t\tfileInfo, err := os.Stat(otherTaskLocal)\n\t\tif fileInfo != nil && err == nil {\n\t\t\t// TaskDirs haven't been built yet, so create it\n\t\t\tnewTaskDir := filepath.Join(a.AllocDir, task.Name)\n\t\t\tif err := os.MkdirAll(newTaskDir, fileMode777); err != nil {\n\t\t\t\treturn fmt.Errorf(\"error creating task %q dir: %w\", task.Name, err)\n\t\t\t}\n\t\t\tlocalDir := filepath.Join(newTaskDir, TaskLocal)\n\t\t\tos.Remove(localDir) // remove an empty local dir if it exists\n\t\t\tif err := os.Rename(otherTaskLocal, localDir); err != nil {\n\t\t\t\treturn fmt.Errorf(\"error moving task %q local dir: %w\", task.Name, err)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// Destroy tears down previously build directory structure.\nfunc (a *AllocDir) Destroy() error {\n\t// Unmount all mounted shared alloc dirs.\n\tmErr := new(multierror.Error)\n\tif err := a.UnmountAll(); err != nil {\n\t\tmErr = multierror.Append(mErr, err)","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/allocdir/alloc_dir.go#L290-L326","documentation":"During Move, when the previous allocation has a task-local directory, the new task directory is created with os.MkdirAll before renaming the local dir in. If MkdirAll fails (permissions, disk full, path conflicts), Move returns 'error creating task %q dir'. The migration is aborted for safety.","triggerScenarios":"os.MkdirAll(a.AllocDir/task.Name, 0777) fails — target alloc dir read-only, disk full, a file exists where the directory should be, or parent dir missing/permission-denied.","commonSituations":"Disk quota exhaustion on nodes with many migrations; leftover files named like task dirs from corrupted prior runs; permissions changed by external tooling; read-only mounts after node incidents.","solutions":["Fix permissions on the target alloc dir","Free disk space / resolve quota pressure","Remove the conflicting non-directory path at a.AllocDir/task.Name","Retry migration after the filesystem issue is resolved"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if st, err := os.Stat(targetTaskDir); err == nil && !st.IsDir() {\n  return fmt.Errorf(\"%s exists and is not a directory\", targetTaskDir)\n}","typeGuard":null,"tryCatchPattern":"if err := allocDir.Move(other, tasks); err != nil && strings.Contains(err.Error(), \"error creating task\") {\n  // check disk space and permissions on alloc dir before retrying\n}","preventionTips":["Monitor node disk space/quota before mass migrations","Clean stale alloc dirs to avoid name collisions","Keep alloc dir permissions consistent across node re-provisioning"],"tags":["filesystem","mkdir","allocation-migration","permissions"],"backgroundTag":"mkdir-permission-denied","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"}