{"record":{"id":"be17841134def541","repo":"kubernetes/kops","slug":"error-setting-mode-on-temp-file-q-w","errorCode":null,"errorMessage":"error setting mode on temp file %q: %w","messagePattern":"error setting mode on temp file %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/files.go","lineNumber":92,"sourceCode":"\tdefer func() {\n\t\tif closeTempFile {\n\t\t\tif err := tempFile.Close(); err != nil {\n\t\t\t\tklog.Warningf(\"error closing tempfile %q: %v\", tempFile.Name(), err)\n\t\t\t}\n\t\t}\n\t\tif deleteTempFile {\n\t\t\tif err := os.Remove(tempFile.Name()); err != nil {\n\t\t\t\tklog.Warningf(\"error removing tempfile %q: %v\", tempFile.Name(), err)\n\t\t\t}\n\t\t}\n\t}()\n\n\tif _, err := io.Copy(tempFile, in); err != nil {\n\t\treturn fmt.Errorf(\"error writing file %q: %v\", tempFile.Name(), err)\n\t}\n\n\tif err := tempFile.Chmod(fileMode); err != nil {\n\t\treturn fmt.Errorf(\"error setting mode on temp file %q: %w\", tempFile.Name(), err)\n\t}\n\n\tif err := tempFile.Close(); err != nil {\n\t\treturn fmt.Errorf(\"error closing temp file %q: %w\", tempFile.Name(), err)\n\t}\n\tcloseTempFile = false\n\n\tif err := os.Rename(tempFile.Name(), destPath); err != nil {\n\t\treturn fmt.Errorf(\"error renaming temp file %q -> %q: %w\", tempFile.Name(), destPath, err)\n\t}\n\tdeleteTempFile = false\n\n\treturn nil\n}\n\nfunc EnsureFileMode(destPath string, fileMode os.FileMode) (bool, error) {\n\tchanged := false\n\tstat, err := os.Lstat(destPath)","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/files.go#L74-L110","documentation":"Thrown by writeFileContents when setting the requested permission bits on the freshly written temp file fails. Chmod on a just-created temp file rarely fails; when it does it is usually an unsupported operation on the filesystem (e.g. NFS/overlay quirks) or the file descriptor was already invalidated.","triggerScenarios":"Thrown at upup/pkg/fi/files.go:92 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check whether the destination filesystem supports chmod (avoid exotic mounts for node files)","Retry the operation — transient NFS/EIO failures on chmod are often sporadic","If persistently unsupported, write to a local filesystem and sync, or relax the file mode requirement"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}