{"record":{"id":"75179ac84a1d7b07","repo":"thanos-io/thanos","slug":"sync-dir","errorCode":null,"errorMessage":"sync dir","messagePattern":"sync dir","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/block/indexheader/binary_reader.go","lineNumber":320,"sourceCode":"\t\t\tdf, err = fileutil.OpenDir(dir)\n\t\t}\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tdefer runutil.CloseWithErrCapture(&err, df, \"dir close\")\n\n\t\tif err := os.RemoveAll(cacheFilename); err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"remove any existing index at path\")\n\t\t}\n\n\t\tvar fileWriter *FileWriter\n\t\tfileWriter, err = NewFileWriter(cacheFilename, len(buf))\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif err := df.Sync(); err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"sync dir\")\n\t\t}\n\t\tbinWriter = fileWriter\n\t} else {\n\t\tbinWriter = NewMemoryWriter(id, len(buf))\n\t}\n\n\tw = &binaryWriter{\n\t\twriter: binWriter,\n\n\t\t// Reusable memory.\n\t\tbuf:   encoding.Encbuf{B: buf},\n\t\tcrc32: newCRC32(),\n\t}\n\n\tw.buf.Reset()\n\tw.buf.PutBE32(MagicIndex)\n\tw.buf.PutByte(BinaryFormatV1)\n","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/block/indexheader/binary_reader.go#L302-L338","documentation":"After creating the FileWriter for the index-header cache file, newBinaryWriter calls df.Sync() on the opened parent directory handle to durably persist the directory entry (the new file's existence). This error wraps the fsync failure on that directory, meaning the OS could not flush the directory metadata to disk.","triggerScenarios":"df.Sync() (directory fsync) returns an error inside newBinaryWriter when cacheFilename != '': disk I/O error, filesystem that does not support directory fsync (some network/FUSE filesystems return EINVAL), or the directory handle became invalid.","commonSituations":"Storing the block cache directory on NFS/CIFS/FUSE mounts that reject fsync on directories; failing disk or full/failing device; container with restricted syscall support.","solutions":["Move the cache directory onto a local filesystem that supports directory fsync (ext4/xfs).","Check dmesg / disk health for underlying I/O errors and fix hardware issues.","If on a network FS that returns EINVAL for dir fsync, reconfigure the storage or patch to skip dir sync there.","Retry WriteBinary after transient I/O errors."],"exampleFix":"// before\nif err := df.Sync(); err != nil {\n    return nil, errors.Wrap(err, \"sync dir\")\n}\n// after\nif err := df.Sync(); err != nil {\n    if errors.Is(err, syscall.EINVAL) {\n        logger.Warn(\"directory fsync unsupported on this filesystem; skipping\")\n    } else {\n        return nil, errors.Wrap(err, \"sync dir\")\n    }\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"_, err := WriteBinary(ctx, bkt, id, cachePath, metrics.DownloadDuration)\nif err != nil {\n    if errors.Is(err, syscall.EINVAL) || errors.Is(err, syscall.ENOTSUP) {\n        // filesystem does not support dir fsync; fall back to memory reader\n        return NewBinaryReader(ctx, logger, bkt, \"\", id, sampling, metrics)\n    }\n    return errors.Wrap(err, \"index header generation\")\n}","preventionTips":["Place block cache directories on local ext4/xfs filesystems, not NFS/FUSE.","Monitor dmesg for I/O errors on cache volumes.","Avoid containers/seccomp policies that block fsync on directories.","Retry transient I/O failures with backoff."],"tags":["filesystem","fsync","durability","io"],"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"}