{"record":{"id":"5c799a10655ca35d","repo":"JuliusBrussee/caveman","slug":"native-session-key-write-w","errorCode":null,"errorMessage":"native session key write: %w","messagePattern":"native session key write: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/nativeruntime/marker.go","lineNumber":41,"sourceCode":"func LoadOrCreateSessionKey(home string) ([]byte, error) {\n\tdir := filepath.Join(home, \"runtime\")\n\tif err := os.MkdirAll(dir, 0o700); err != nil {\n\t\treturn nil, fmt.Errorf(\"native session key mkdir: %w\", err)\n\t}\n\tif err := os.Chmod(dir, 0o700); err != nil {\n\t\treturn nil, fmt.Errorf(\"native session key chmod dir: %w\", err)\n\t}\n\tpath := filepath.Join(dir, \"session.key\")\n\tkey := make([]byte, sessionKeyBytes)\n\tif _, err := rand.Read(key); err != nil {\n\t\treturn nil, fmt.Errorf(\"native session key random: %w\", err)\n\t}\n\tfile, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o600)\n\tif err == nil {\n\t\tif _, writeErr := file.Write(key); writeErr != nil {\n\t\t\t_ = file.Close()\n\t\t\t_ = os.Remove(path)\n\t\t\treturn nil, fmt.Errorf(\"native session key write: %w\", writeErr)\n\t\t}\n\t\tif syncErr := file.Sync(); syncErr != nil {\n\t\t\t_ = file.Close()\n\t\t\t_ = os.Remove(path)\n\t\t\treturn nil, fmt.Errorf(\"native session key sync: %w\", syncErr)\n\t\t}\n\t\tif closeErr := file.Close(); closeErr != nil {\n\t\t\treturn nil, fmt.Errorf(\"native session key close: %w\", closeErr)\n\t\t}\n\t\treturn key, nil\n\t}\n\tif !errors.Is(err, os.ErrExist) {\n\t\treturn nil, fmt.Errorf(\"native session key create: %w\", err)\n\t}\n\tkey, err = os.ReadFile(path)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"native session key read: %w\", err)\n\t}","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/766dce6b1394ebb56a3090748d5a0240a5aefb36/proxy/internal/nativeruntime/marker.go#L23-L59","documentation":"The O_EXCL create of session.key succeeded but writing the 32 bytes failed; the code closes the fd and deletes the partial file, so no corrupt key is ever left behind. The wrapped error is typically ENOSPC (disk full), EDQUOT (quota exceeded), or EIO from failing or removable storage. A clean retry succeeds once space exists.","triggerScenarios":"First-ever startup on a 100%-full volume; user quota exceeded on a network home; a flaky USB/removable drive holding CAVEMAN_HOME; an NFS stale file handle surfacing during the write.","commonSituations":"Laptops with full disks; shared hosts with per-user quotas; first run right after restoring an image onto a small partition.","solutions":["Free space on the volume holding home (df -h <home>) or raise the quota","Re-run startup — the partial file was already removed so the retry mints cleanly","Point CAVEMAN_HOME at a volume with headroom","If the error is EIO, check dmesg and the device's SMART health"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"func hasFreeSpace(path string, want uint64) error {\n\tvar st syscall.Statfs_t\n\tif err := syscall.Statfs(path, &st); err != nil {\n\t\treturn err\n\t}\n\tif free := st.Bavail * uint64(st.Bsize); free < want {\n\t\treturn fmt.Errorf(\"only %d bytes free under %s — key creation needs %d\", free, path, want)\n\t}\n\treturn nil\n}\n\n// before first-startup key creation\nif err := hasFreeSpace(home, 1<<20); err != nil {\n\treturn err\n}","typeGuard":null,"tryCatchPattern":"key, err := nativeruntime.LoadOrCreateSessionKey(home)\nif err != nil {\n\tif errors.Is(err, syscall.ENOSPC) || errors.Is(err, syscall.EDQUOT) {\n\t\t// clean state guaranteed: the partial file was already removed — safe to retry after freeing space\n\t\tlog.Print(\"free disk space or raise the quota, then restart\")\n\t}\n\treturn err\n}","preventionTips":["Run deployments with disk-space alerts well above zero so key creation never races a full volume","Point CAVEMAN_HOME at a volume with headroom instead of a full root partition","Treat ENOSPC/EDQUOT on first startup as transient: the function self-cleans, so a restart after cleanup is sufficient","For quota-managed network homes, request at least a few MB of slack"],"tags":["go","filesystem","disk-full","io"],"backgroundTag":"disk-full-write-failure","analyzedSha":"766dce6b1394ebb56a3090748d5a0240a5aefb36","analyzedAt":"2026-08-18T03:14:35.516Z","contentChangedAt":"2026-08-18T03:14:35.516Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}