netbirdio/netbird · error

failed to write file

Error message

failed to write file

What it means

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.

Source

Thrown at upload-server/server/local.go:148

		log.Errorf("Failed to create upload dir: %v", err)
		return
	}

	flags := os.O_WRONLY | os.O_CREATE | os.O_EXCL
	f, err := os.OpenFile(filePath, flags, 0600)
	if err != nil {
		if os.IsExist(err) {
			http.Error(w, "file already exists", http.StatusConflict)
			return
		}
		http.Error(w, "failed to create file", http.StatusInternalServerError)
		log.Errorf("Failed to create file %s: %v", filePath, err)
		return
	}
	defer func() { _ = f.Close() }()

	if _, err = f.Write(body); err != nil {
		http.Error(w, "failed to write file", http.StatusInternalServerError)
		log.Errorf("Failed to write file %s: %v", filePath, err)
		return
	}

	log.Infof("Uploaded file %s", filePath)
	w.WriteHeader(http.StatusOK)
}

View on GitHub (pinned to 93e97f4bf1)

Solutions

  1. Check df -h and df -i on the STORE_DIR filesystem; free space or raise the quota
  2. Verify the storage is a healthy local volume, not a flaky network mount (dmesg, mount output)
  3. Confirm the body is under the 150 MiB MaxBytesReader cap so the failure is at write time, not the 413 read stage
Defensive patterns

Strategy: retry

Validate before calling

// before upload, cheap client-side size guard (server cap is 150 MiB)
if fi, err := os.Stat(path); err == nil && fi.Size() > 150<<20 {
	return fmt.Errorf("file exceeds 150 MiB upload limit")
}

Try / catch

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.

Prevention

When it happens

Trigger: 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.

Common situations: Small ephemeral container/CI disks collecting debug bundles; quota-limited shared hosting; network storage returning I/O errors under load.

Related errors


AI-assisted analysis of netbirdio/netbird@93e97f4bf1 (2026-08-16). Data as JSON: /api/errors/bb8e5d25dcbd1f63. Report an issue: GitHub.