{"record":{"id":"3c900551d0c48482","repo":"thanos-io/thanos","slug":"sync-temporary-dir-file","errorCode":null,"errorMessage":"sync temporary dir file","messagePattern":"sync temporary dir file","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/block/writer.go","lineNumber":123,"sourceCode":"\t\tif err != nil {\n\t\t\terr = tsdb_errors.NewMulti(err, tsdb_errors.CloseAll(d.closers)).Err()\n\t\t\tif err := os.RemoveAll(d.bTmp); err != nil {\n\t\t\t\tlevel.Error(d.logger).Log(\"msg\", \"removed tmp folder failed after block(s) write\", \"err\", err.Error())\n\t\t\t}\n\t\t}\n\t}()\n\tdf, err := fileutil.OpenDir(d.bTmp)\n\tif err != nil {\n\t\treturn tsdb.BlockStats{}, errors.Wrap(err, \"open temporary block dir\")\n\t}\n\tdefer func() {\n\t\tif df != nil {\n\t\t\terr = tsdb_errors.NewMulti(err, df.Close()).Err()\n\t\t}\n\t}()\n\n\tif err := df.Sync(); err != nil {\n\t\treturn tsdb.BlockStats{}, errors.Wrap(err, \"sync temporary dir file\")\n\t}\n\n\t// Close temp dir before rename block dir (for windows platform).\n\tif err = df.Close(); err != nil {\n\t\treturn tsdb.BlockStats{}, errors.Wrap(err, \"close temporary dir\")\n\t}\n\tdf = nil\n\n\tif err := tsdb_errors.CloseAll(d.closers); err != nil {\n\t\td.closers = nil\n\t\treturn tsdb.BlockStats{}, err\n\t}\n\td.closers = nil\n\n\t// Block files successfully written, make them visible by moving files from tmp dir.\n\tif err := fileutil.Replace(filepath.Join(d.bTmp, IndexFilename), filepath.Join(d.bDir, IndexFilename)); err != nil {\n\t\treturn tsdb.BlockStats{}, errors.Wrap(err, \"replace index file\")\n\t}","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/block/writer.go#L105-L141","documentation":"Flush fails when df.Sync() cannot flush the temporary directory's directory entry to stable storage. Persisting directory entries (so renamed chunk/index files survive crashes) is required for durable block writes; failure here aborts publication of the block.","triggerScenarios":"Calling fsync on the opened temp dir failing — usually ENOSPC, EIO, or unsupported fsync-on-directory on exotic filesystems, or the dir having been closed/invalidated.","commonSituations":"Disk full or failing storage device; network filesystems (some NFS/S3-FUSE mounts) that don't support directory fsync; kernel/device errors under heavy IO load.","solutions":["Verify disk health and free space on the target volume.","Avoid storing block dirs on filesystems that reject directory fsync (use local/ext4/xfs).","Retry Flush after transient EIO; investigate dmesg for device errors.","Delete the incomplete tmp dir and re-create the block."],"exampleFix":"// before (unsupported FS)\n$ df -T /data  ->  nfs\n// after: migrate block storage to a local filesystem\n$ df -T /data  ->  ext4","handlingStrategy":"retry","validationCode":"if free, err := diskFree(bdir); err == nil && free < minRequiredBytes {\n    return fmt.Errorf(\"low disk space before flush: %d bytes\", free)\n}","typeGuard":null,"tryCatchPattern":"var lastErr error\nfor i := 0; i < 3; i++ {\n    if _, err := d.Flush(ctx); err != nil {\n        if strings.Contains(err.Error(), \"sync temporary dir file\") {\n            lastErr = err\n            time.Sleep(backoff(i))\n            continue\n        }\n        return err\n    }\n    return nil\n}\nreturn lastErr","preventionTips":["Keep block storage on local filesystems that support directory fsync.","Monitor device health (SMART) and free space on compaction volumes.","Handle EIO with bounded retries and rebuild the block on persistent failure."],"tags":["go","block-writer","fsync","filesystem"],"backgroundTag":"file-write-failed","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}