{"record":{"id":"e4d829d9f972a533","repo":"kubernetes/kops","slug":"error-creating-temp-file-in-q-w-e4d829","errorCode":null,"errorMessage":"error creating temp file in %q: %w","messagePattern":"error creating temp file in %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/pkg/vfs/sshfs.go","lineNumber":188,"sourceCode":"\nfunc (p *SSHPath) WriteFile(ctx context.Context, data io.ReadSeeker, acl ACL) error {\n\tsftpClient, err := p.newClient(ctx)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer sftpClient.Close()\n\n\tdir := path.Dir(p.path)\n\terr = mkdirAll(sftpClient, dir)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\ttempfile := path.Join(dir, fmt.Sprintf(\".tmp-%d\", rand.Int63()))\n\tf, err := sftpClient.Create(tempfile)\n\tif err != nil {\n\t\t// TODO: Retry if concurrently created?\n\t\treturn fmt.Errorf(\"error creating temp file in %q: %w\", dir, err)\n\t}\n\n\t// Note from here on in we have to close f and delete or rename the temp file\n\tshouldClose := true\n\tdefer func() {\n\t\tif shouldClose {\n\t\t\t// Something went wrong; try to close the temp file\n\t\t\tif err := f.Close(); err != nil {\n\t\t\t\tklog.Warningf(\"unable to close temp file %q: %v\", tempfile, err)\n\t\t\t}\n\t\t}\n\t}()\n\n\tdeleteTempFile := true\n\tdefer func() {\n\t\tif deleteTempFile {\n\t\t\t// Something went wrong; try to remove the temp file\n\t\t\tif err := sftpClient.Remove(tempfile); err != nil {","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/util/pkg/vfs/sshfs.go#L170-L206","documentation":"WriteFile stages data in a temp file named .tmp-<random> inside the target directory, created via sftpClient.Create. If the SFTP server refuses to create that temp file, this error wraps the cause. It indicates the directory exists (mkdirAll passed) but a new file cannot be created there.","triggerScenarios":"WriteFile on an SSHPath where the directory is not writable by the SFTP user, the disk is full, or (rarely) the random temp name collides with an existing file that cannot be opened for writing.","commonSituations":"Writing node bootstrap files to /etc/kubernetes/manifests with a non-root SFTP user; full disk on the master node; immutable directory; SFTP chroot/subsystem restricting writes to certain paths.","solutions":["Check free disk space on the remote host (`df -h <dir>`) and free space if full.","Verify the SSH user has write permission on the directory; `sudo chown`/`chmod` it or pre-create writable staging.","If an old .tmp-* file blocks creation (stale from a crashed run), remove it: `rm <dir>/.tmp-*`.","Retry — the comment notes concurrent creation is possible; the random suffix makes collisions unlikely."],"exampleFix":"// before: full disk on remote host\nFilesystem / has 0 available\n// after\n$ ssh host 'rm -rf /var/log/journal/*old*' && kops replace ... # retry succeeds","handlingStrategy":"validation","validationCode":"// verify disk space and writability on the remote directory before writing\nout := sshRun(host, fmt.Sprintf(\"df --output=avail -B1 %s | tail -1; test -w %s && echo ok\", dir, dir))\n// require available > neededBytes and \"ok\" present","typeGuard":null,"tryCatchPattern":"err := path.WriteFile(ctx, data, acl)\nif err != nil && strings.Contains(err.Error(), \"error creating temp file\") {\n    // clean stale temp files then retry once\n    sshRun(host, fmt.Sprintf(\"rm -f %s/.tmp-*\", dir))\n    return path.WriteFile(ctx, data, acl)\n}","preventionTips":["Monitor remote disk usage on nodes that receive cluster state files.","Clean stale .tmp-* files left by crashed runs.","Ensure the SFTP subsystem (internal-sftp) is not chrooted to a read-only tree."],"tags":["ssh","sftp","filesystem","temp-file"],"backgroundTag":"sftp-temp-file-creation-failed","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"}