{"record":{"id":"413439b9ffcf6e00","repo":"hashicorp/nomad","slug":"error-creating-file-w","errorCode":null,"errorMessage":"error creating file: %w","messagePattern":"error creating file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/allocwatcher/alloc_watcher.go","lineNumber":653,"sourceCode":"\t\t\t\t\treturn fmt.Errorf(\"error evaluating symlink: %w\", err)\n\t\t\t\t} else if escapes {\n\t\t\t\t\treturn fmt.Errorf(\"archive contains symlink that escapes alloc dir\")\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcontinue\n\t\t}\n\t\t// If the header is a file, we write to a file\n\t\tif hdr.Typeflag == tar.TypeReg {\n\t\t\tfPath := filepath.Join(dest, hdr.Name)\n\t\t\tif _, err := os.Lstat(fPath); err == nil {\n\t\t\t\tif err := os.Remove(fPath); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"error removing existing file: %w\", err)\n\t\t\t\t}\n\t\t\t}\n\t\t\tf, err := os.Create(fPath)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error creating file: %w\", err)\n\t\t\t}\n\n\t\t\t// Setting the permissions of the file as the origin.\n\t\t\tif err := f.Chmod(os.FileMode(hdr.Mode)); err != nil {\n\t\t\t\tf.Close()\n\t\t\t\treturn fmt.Errorf(\"error chmoding file %w\", err)\n\t\t\t}\n\n\t\t\t// Can't change owner if not root or on Windows.\n\t\t\tif euid == 0 {\n\t\t\t\tif err := f.Chown(hdr.Uid, hdr.Gid); err != nil {\n\t\t\t\t\tf.Close()\n\t\t\t\t\treturn fmt.Errorf(\"error chowning file %w\", err)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// We write in chunks so that we can test if the client\n\t\t\t// is still alive","sourceCodeStart":635,"sourceCodeEnd":671,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/allocwatcher/alloc_watcher.go#L635-L671","documentation":"During tar extraction, after removing any prior entry, Nomad calls os.Create on the destination file path. This error is returned when file creation fails, typically because the parent directory does not exist or lacks write permission.","triggerScenarios":"streamAllocDir processes a tar.TypeReg header and os.Create(filepath.Join(dest, hdr.Name)) returns an error (ENOENT missing parent dir, EACCES, ENOSPC).","commonSituations":"Archive lists a file before its parent directory entry; disk full on the destination node; permission mismatch after running the client as a different user; path collisions with an existing directory.","solutions":["Verify the archive contains directory entries before the files inside them","Check free disk space (ENOSPC) on the destination node","Fix write permissions/ownership of the alloc dir for the Nomad client user","Clean stale/partial extraction state and retry the migration"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Pre-flight checks before migration:\n// free disk space (syscall.Statfs) and write access to the destination (os.WriteFile probe)","typeGuard":null,"tryCatchPattern":"if err := watcher.Wait(ctx); err != nil {\n    if strings.Contains(err.Error(), \"error creating file\") {\n        if errors.Is(err, syscall.ENOSPC) { alertDiskFull(); return err }\n        os.RemoveAll(dest)\n        return retryMigration(ctx, alloc)\n    }\n    return err\n}","preventionTips":["Monitor disk space on client nodes and alert before full","Ensure the client user owns the data/alloc directories","Pin consistent Nomad versions so archive ordering (dirs before files) matches"],"tags":["nomad","filesystem","file-extraction","permissions"],"backgroundTag":"file-create-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"}