{"record":{"id":"b0bba210f3d824ae","repo":"benbjohnson/litestream","slug":"webdav-cannot-create-temp-file-w","errorCode":null,"errorMessage":"webdav: cannot create temp file: %w","messagePattern":"webdav: cannot create temp file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"webdav/replica_client.go","lineNumber":259,"sourceCode":"\n\tfilename := litestream.LTXFilePath(c.Path, level, minTXID, maxTXID)\n\n\tvar buf bytes.Buffer\n\tteeReader := io.TeeReader(rd, &buf)\n\n\thdr, _, err := ltx.PeekHeader(teeReader)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"extract timestamp from LTX header: %w\", err)\n\t}\n\ttimestamp := time.UnixMilli(hdr.Timestamp).UTC()\n\n\t// Stage to temporary file to get seekable reader with known size.\n\t// This ensures compatibility with all WebDAV servers and avoids the\n\t// unreliable chunked transfer encoding that causes silent data loss\n\t// on common configurations (Nginx+FastCGI, Lighttpd, Apache+FastCGI).\n\ttmpFile, err := os.CreateTemp(\"\", \"litestream-webdav-*.ltx\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"webdav: cannot create temp file: %w\", err)\n\t}\n\tdefer func() {\n\t\t_ = tmpFile.Close()\n\t\t_ = os.Remove(tmpFile.Name())\n\t}()\n\n\tfullReader := io.MultiReader(&buf, rd)\n\n\tsize, err := io.Copy(tmpFile, fullReader)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"webdav: cannot copy to temp file: %w\", err)\n\t}\n\n\tif _, err := tmpFile.Seek(0, io.SeekStart); err != nil {\n\t\treturn nil, fmt.Errorf(\"webdav: cannot seek temp file: %w\", err)\n\t}\n\n\tif err := client.MkdirAll(path.Dir(filename), 0755); err != nil {","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/webdav/replica_client.go#L241-L277","documentation":"WriteLTXFile stages the incoming LTX stream to a temporary local file (to obtain a seekable reader with known size for Content-Length uploads). This error wraps the os.CreateTemp failure, meaning the local filesystem refused to create the temp file.","triggerScenarios":"os.CreateTemp(\"\", \"litestream-webdav-*.ltx\") fails: TMPDIR points to a nonexistent/unwritable directory, or the disk holding os.TempDir() is full.","commonSituations":"Containers with read-only /tmp, TMPDIR misconfigured in systemd units or Docker, full disk on the litestream host.","solutions":["Check disk space on the partition holding the temp dir (df -h $TMPDIR)","Verify TMPDIR is set to a writable directory, or unset it to use /tmp","Fix permissions on the temp directory (writable by the litestream user)","Mount a writable tmpfs/emptyDir at /tmp in the container"],"exampleFix":"// before\nTMPDIR=/nonexistent litestream replicate ...  // fails\n// after\nmkdir -p /var/tmp/litestream && TMPDIR=/var/tmp/litestream litestream replicate ...","handlingStrategy":"validation","validationCode":"tmpDir := os.TempDir()\nif st, err := os.Stat(tmpDir); err != nil || !st.IsDir() { return fmt.Errorf(\"temp dir %s unavailable\", tmpDir) }\nprobe, err := os.CreateTemp(tmpDir, \"probe-*\"); if err != nil { return err }; probe.Close(); os.Remove(probe.Name())","typeGuard":null,"tryCatchPattern":"if err := runReplication(ctx); err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && errors.Is(pe.Err, syscall.ENOSPC) { /* free disk or relocate TMPDIR */ }\n}","preventionTips":["Monitor disk space on the temp partition","Pin TMPDIR to a known writable location in containers","Ensure /tmp is writable by the litestream service user"],"tags":["filesystem","temp-file","disk"],"backgroundTag":"file-write-failed","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}