{"record":{"id":"bb8e5d25dcbd1f63","repo":"netbirdio/netbird","slug":"failed-to-write-file","errorCode":null,"errorMessage":"failed to write file","messagePattern":"failed to write file","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"upload-server/server/local.go","lineNumber":148,"sourceCode":"\t\tlog.Errorf(\"Failed to create upload dir: %v\", err)\n\t\treturn\n\t}\n\n\tflags := os.O_WRONLY | os.O_CREATE | os.O_EXCL\n\tf, err := os.OpenFile(filePath, flags, 0600)\n\tif err != nil {\n\t\tif os.IsExist(err) {\n\t\t\thttp.Error(w, \"file already exists\", http.StatusConflict)\n\t\t\treturn\n\t\t}\n\t\thttp.Error(w, \"failed to create file\", http.StatusInternalServerError)\n\t\tlog.Errorf(\"Failed to create file %s: %v\", filePath, err)\n\t\treturn\n\t}\n\tdefer func() { _ = f.Close() }()\n\n\tif _, err = f.Write(body); err != nil {\n\t\thttp.Error(w, \"failed to write file\", http.StatusInternalServerError)\n\t\tlog.Errorf(\"Failed to write file %s: %v\", filePath, err)\n\t\treturn\n\t}\n\n\tlog.Infof(\"Uploaded file %s\", filePath)\n\tw.WriteHeader(http.StatusOK)\n}\n","sourceCodeStart":130,"sourceCodeEnd":156,"githubUrl":"https://github.com/netbirdio/netbird/blob/93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c/upload-server/server/local.go#L130-L156","documentation":"HTTP 500 returned when writing the request body to the freshly created file fails (f.Write returns an error). The file was opened successfully, so the failure is at the write(2) level; the server logs 'Failed to write file <path>' with the errno.","triggerScenarios":"ENOSPC: disk or quota exhausted mid-write (bodies up to maxUploadSize = 150 MiB are fully read, then written); EDQUOT quota exceeded; EIO from a failing disk or an unstable NFS/FUSE mount; cgroup io limits surfacing as errors.","commonSituations":"Small ephemeral container/CI disks collecting debug bundles; quota-limited shared hosting; network storage returning I/O errors under load.","solutions":["Check df -h and df -i on the STORE_DIR filesystem; free space or raise the quota","Verify the storage is a healthy local volume, not a flaky network mount (dmesg, mount output)","Confirm the body is under the 150 MiB MaxBytesReader cap so the failure is at write time, not the 413 read stage"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// before upload, cheap client-side size guard (server cap is 150 MiB)\nif fi, err := os.Stat(path); err == nil && fi.Size() > 150<<20 {\n\treturn fmt.Errorf(\"file exceeds 150 MiB upload limit\")\n}","typeGuard":null,"tryCatchPattern":"Retry the whole upload with a fresh URL and short backoff (write errors can be transient quota/IO flush issues); after 2-3 failures treat it as capacity and alert the operator to check df on STORE_DIR.","preventionTips":["Monitor free space and inodes on the STORE_DIR filesystem","Prefer a local volume over NFS/FUSE for upload storage","Keep bodies under the 150 MiB MaxBytesReader cap to fail at read time (413) rather than mid-write"],"tags":["filesystem","disk-full","upload","go"],"backgroundTag":null,"analyzedSha":"93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c","analyzedAt":"2026-08-16T03:09:19.136Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}