{"record":{"id":"98e75c1a376b6cf4","repo":"nats-io/nats-server","slug":"failed-to-sync-temporary-file-w","errorCode":null,"errorMessage":"failed to sync temporary file: %w","messagePattern":"failed to sync temporary file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"server/filestore.go","lineNumber":8067,"sourceCode":"\t\t\tOriginalSize: uint64(originalSize),\n\t\t}\n\t\tbuf = append(meta.MarshalMetadata(), buf...)\n\t}\n\n\t// Re-encrypt the block if necessary.\n\tif err = mb.encryptOrDecryptIfNeeded(buf); err != nil {\n\t\treturn errorCleanup(err)\n\t}\n\n\t// Write the new block data (which might be compressed or encrypted) to the\n\t// temporary file.\n\tif n, err := tmpFD.Write(buf); err != nil {\n\t\treturn errorCleanup(fmt.Errorf(\"failed to write to temporary file: %w\", err))\n\t} else if n != len(buf) {\n\t\treturn errorCleanup(fmt.Errorf(\"short write to temporary file (%d != %d)\", n, len(buf)))\n\t}\n\tif err := tmpFD.Sync(); err != nil {\n\t\treturn errorCleanup(fmt.Errorf(\"failed to sync temporary file: %w\", err))\n\t}\n\tif err := tmpFD.Close(); err != nil {\n\t\treturn errorCleanup(fmt.Errorf(\"failed to close temporary file: %w\", err))\n\t}\n\n\t// Now replace the original file with the newly updated temp file.\n\tif err := os.Rename(tmpFN, origFN); err != nil {\n\t\treturn fmt.Errorf(\"failed to move temporary file into place: %w\", err)\n\t}\n\n\t// Since the message block might be retained in memory, make sure the\n\t// compression algorithm is up-to-date, since this will be needed when\n\t// compacting or truncating.\n\tmb.cmp = alg\n\n\t// Also update rbytes\n\tmb.rbytes = uint64(len(buf))\n","sourceCodeStart":8049,"sourceCodeEnd":8085,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/filestore.go#L8049-L8085","documentation":"Returned when fsync on the temporary block file fails during a file-store message block update. The store calls tmpFD.Sync() to guarantee durability before renaming the temp file into place; failure aborts the update via errorCleanup, preserving the original block.","triggerScenarios":"tmpFD.Sync() returns an error while syncing new block data to stable storage during a message block update (write/update path in filestore).","commonSituations":"Disk I/O errors, storage device failures/disconnections, virtualization or SAN issues where flush/fsync fails, or the underlying file becoming unavailable mid-update.","solutions":["Check kernel logs (dmesg) and SMART status for disk I/O errors.","Verify the storage device is healthy and connected (especially cloud volumes/SAN).","Run filesystem check (fsck) on the affected volume after taking the server offline.","Retry the operation once storage is healthy; temp file is cleaned up automatically."],"exampleFix":"// after: verify disk health\n// smartctl -H /dev/sda && dmesg | grep -i \"i/o error\"","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"failed to sync temporary file\") {\n    // fsync failure: check storage health before retrying\n    // alert ops and verify device via smartctl/dmesg\n}","preventionTips":["Monitor disk SMART health and I/O error logs.","Use redundant/healthy storage for JetStream data.","Avoid storage backends that don't guarantee fsync semantics.","Set durability-aware alerts for fsync failures in server logs."],"tags":["filestore","fsync","io","jetstream","go"],"backgroundTag":"fsync-failed","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}