{"record":{"id":"0791b4b1d4f35d65","repo":"fatedier/frp","slug":"failed-to-close-temp-file-w","errorCode":null,"errorMessage":"failed to close temp file: %w","messagePattern":"failed to close temp file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/config/source/store.go","lineNumber":169,"sourceCode":"\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create temp file: %w\", err)\n\t}\n\n\tif _, err := f.Write(data); err != nil {\n\t\tf.Close()\n\t\tos.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"failed to write temp file: %w\", err)\n\t}\n\n\tif err := f.Sync(); err != nil {\n\t\tf.Close()\n\t\tos.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"failed to sync temp file: %w\", err)\n\t}\n\n\tif err := f.Close(); err != nil {\n\t\tos.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"failed to close temp file: %w\", err)\n\t}\n\n\tif err := os.Rename(tmpPath, s.config.Path); err != nil {\n\t\tos.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"failed to rename temp file: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc (s *StoreSource) persistOrRollbackUnlocked(rollback func()) error {\n\tif err := s.saveToFileUnlocked(); err != nil {\n\t\trollback()\n\t\treturn fmt.Errorf(\"failed to persist: %w\", err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/fatedier/frp/blob/6c8a8d0a97d03b44e9528d30b30c70cb9d61b405/pkg/config/source/store.go#L151-L187","documentation":"Closing the temp file failed after write and fsync succeeded. Because fsync already flushed data, this is the rarest failure of the atomic-write sequence; it surfaces delayed writeback errors or fd-level problems. The temp file is removed and the change rolled back.","triggerScenarios":"A writeback error deferred until close(2); file descriptor issues in unusual runtimes; almost never triggered by user input or permissions.","commonSituations":"Same class as sync/write errors — failing storage or exotic filesystems; otherwise negligible probability.","solutions":["Treat it like a storage-health signal: check dmesg for I/O errors","Verify the filesystem with fsck (unmounted) or move the store to a local healthy volume","Retry the operation after remediation; state was rolled back consistently"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := store.RemoveProxy(name); err != nil {\n\tif strings.Contains(err.Error(), \"failed to close temp file\") {\n\t\t// fsync already succeeded; verify the file on disk and retry once\n\t} else {\n\t\treturn err\n\t}\n}","preventionTips":["Treat any close-stage failure as a storage-health signal and investigate dmesg","Move the store off exotic filesystems that mishandle flush-on-close"],"tags":["filesystem","io","storage-health","go"],"backgroundTag":null,"analyzedSha":"6c8a8d0a97d03b44e9528d30b30c70cb9d61b405","analyzedAt":"2026-08-15T06:53:27.215Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}