{"record":{"id":"b7246e9cd9cf3422","repo":"JuliusBrussee/caveman","slug":"native-session-key-sync-w","errorCode":null,"errorMessage":"native session key sync: %w","messagePattern":"native session key sync: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/nativeruntime/marker.go","lineNumber":46,"sourceCode":"\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}\n\tif len(key) != sessionKeyBytes {\n\t\treturn nil, fmt.Errorf(\"native session key length = %d, want %d\", len(key), sessionKeyBytes)\n\t}\n\tif err := os.Chmod(path, 0o600); err != nil {\n\t\treturn nil, fmt.Errorf(\"native session key chmod: %w\", err)","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/766dce6b1394ebb56a3090748d5a0240a5aefb36/proxy/internal/nativeruntime/marker.go#L28-L64","documentation":"file.Sync (fsync) on the newly written session.key failed after the in-buffer write reported success; the file is closed and removed. Many filesystems first surface ENOSPC or media EIO at fsync time (delayed allocation, NFS page commit), so disk-full and failing storage dominate even though Write 'worked'. The removal keeps creation atomic: no half-persisted key exists.","triggerScenarios":"A volume that accepts buffered writes but is full at block-commit time (ext4 delayed allocation, NFS commit); a failing disk returning EIO on flush; a network home whose server rejects the commit.","commonSituations":"Full root partitions with buffered writes; NFS homes with server-side commit errors; failing HDD/SSD media; VMs on thin-provisioned backing store that hit the storage limit.","solutions":["Check and free space: df -h <home> (and df -i <home> for inode exhaustion)","Check dmesg / storage SMART data for I/O errors","Retry after cleanup — the failed partial file was already deleted","Move home onto healthy local storage"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"key, err := nativeruntime.LoadOrCreateSessionKey(home)\nif err != nil {\n\tif strings.Contains(err.Error(), \"session key sync\") {\n\t\t// fsync surfaced ENOSPC/EIO after a buffered write — check df -h and dmesg, then retry;\n\t\t// the half-written file was already unlinked, so the retry starts clean\n\t\tlog.Print(\"fsync failed — verify disk health and free space, then restart\")\n\t}\n\treturn err\n}","preventionTips":["Monitor disk space and storage SMART health — fsync is where failing drives first announce themselves","Avoid placing CAVEMAN_HOME on thin-provisioned or quota-limited backing that can reject commits","After any sync failure, verify the file is gone (ls <home>/runtime) before restarting","Keep network-mounted homes out of the key path when the server has a history of commit errors"],"tags":["go","filesystem","disk-full","fsync"],"backgroundTag":"fsync-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"}