{"record":{"id":"1388a06cdc75664a","repo":"thanos-io/thanos","slug":"open-chunk-writer-1388a0","errorCode":null,"errorMessage":"open chunk writer","messagePattern":"open chunk writer","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/block/writer.go","lineNumber":88,"sourceCode":"\tdefer func() {\n\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(bTmp); err != nil {\n\t\t\t\tlevel.Error(logger).Log(\"msg\", \"removed tmp folder after failed compaction\", \"err\", err.Error())\n\t\t\t}\n\t\t}\n\t}()\n\n\tif err = os.RemoveAll(bTmp); err != nil {\n\t\treturn nil, err\n\t}\n\tif err = os.MkdirAll(bTmp, 0750); err != nil {\n\t\treturn nil, err\n\t}\n\n\tchunkw, err := chunks.NewWriter(filepath.Join(bTmp, ChunksDirname))\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"open chunk writer\")\n\t}\n\td.closers = append(d.closers, chunkw)\n\n\t// TODO(bwplotka): Setup instrumentedChunkWriter if we want to upstream this code.\n\n\tindexw, err := index.NewWriter(ctx, filepath.Join(bTmp, IndexFilename))\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"open index writer\")\n\t}\n\td.closers = append(d.closers, indexw)\n\td.statsGatheringSeriesWriter = statsGatheringSeriesWriter{iw: indexw, cw: chunkw}\n\treturn d, nil\n}\n\nfunc (d *DiskWriter) Flush() (_ tsdb.BlockStats, err error) {\n\tdefer func() {\n\t\tif err != nil {\n\t\t\terr = tsdb_errors.NewMulti(err, tsdb_errors.CloseAll(d.closers)).Err()","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/block/writer.go#L70-L106","documentation":"NewDiskWriter fails when chunks.NewWriter cannot open a chunk segment writer in the temporary block dir's chunks/ directory. This prevents any block data from being written and aborts block creation immediately.","triggerScenarios":"chunks.NewWriter failing on <bTmp>/chunks — typically because the directory cannot be created/opened: permission denied, disk full, path is a file, or the underlying OS open failed.","commonSituations":"Insufficient permissions on the parent data directory; disk quota/full volume; bTmp path colliding with an existing non-directory file; read-only filesystem mount.","solutions":["Check write permissions on the parent directory used for the block temp dir.","Verify free disk space and that the filesystem is not read-only.","Ensure the target path is not occupied by a regular file named 'chunks'.","Clean stale temporary block dirs (<bTmp> leftovers) and retry."],"exampleFix":"// before\nd, err := NewDiskWriter(ctx, \"/data/store/01BK...\", logging.NewNopLogger()) // /data/store not writable\n// after\nos.Chmod(\"/data/store\", 0755)\nd, err := NewDiskWriter(ctx, \"/data/store/01BK...\", logging.NewNopLogger())","handlingStrategy":"try-catch","validationCode":"chunksParent := filepath.Join(bdir, \"tmp-for-creation\")\nif err := os.MkdirAll(chunksParent, 0750); err != nil {\n    return fmt.Errorf(\"cannot create tmp dir %s: %w\", chunksParent, err)\n}\nif err := unix.Access(chunksParent, unix.W_OK); err != nil {\n    return fmt.Errorf(\"tmp dir not writable: %w\", err)\n}","typeGuard":"func canWriteDir(path string) bool {\n    fi, err := os.Stat(path)\n    return err == nil && fi.IsDir() && unix.Access(path, unix.W_OK) == nil\n}","tryCatchPattern":"d, err := block.NewDiskWriter(ctx, bdir, logger)\nif err != nil {\n    if strings.Contains(err.Error(), \"open chunk writer\") {\n        return fmt.Errorf(\"filesystem issue creating chunks writer for %s: %w\", bdir, err)\n    }\n    return err\n}","preventionTips":["Pre-flight check disk space and write permissions before block creation.","Clean up stale tmp-for-creation directories after failed writes.","Ensure block storage is on a writable local filesystem, not a read-only mount."],"tags":["go","block-writer","file-open-failed","filesystem"],"backgroundTag":"file-open-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"}