{"record":{"id":"2ad4d2b3d52e6995","repo":"thanos-io/thanos","slug":"close-block","errorCode":null,"errorMessage":"close block","messagePattern":"close block","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/store/bucket.go","lineNumber":939,"sourceCode":"}\n\nfunc (s *BucketStore) removeBlock(id ulid.ULID) error {\n\ts.mtx.Lock()\n\tb, ok := s.blocks[id]\n\tif ok {\n\t\tlset := labels.FromMap(b.meta.Thanos.Labels)\n\t\ts.blockSets[lset.Hash()].remove(id)\n\t\tdelete(s.blocks, id)\n\t}\n\ts.mtx.Unlock()\n\n\tif !ok {\n\t\treturn nil\n\t}\n\n\ts.metrics.blocksLoaded.Dec()\n\tif err := b.Close(); err != nil {\n\t\treturn errors.Wrap(err, \"close block\")\n\t}\n\n\tif b.dir == \"\" {\n\t\treturn nil\n\t}\n\n\treturn os.RemoveAll(b.dir)\n}\n\n// TimeRange returns the minimum and maximum timestamp of data available in the store.\nfunc (s *BucketStore) TimeRange() (mint, maxt int64) {\n\ts.mtx.RLock()\n\tdefer s.mtx.RUnlock()\n\n\tmint = math.MaxInt64\n\tmaxt = math.MinInt64\n\n\tfor _, b := range s.blocks {","sourceCodeStart":921,"sourceCodeEnd":957,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/store/bucket.go#L921-L957","documentation":"Wraps b.Close() failure while removing/unloading a block from the BucketStore. The block was found in the loaded map and its metrics decremented, but closing the block's index reader, chunk pool, or temp directory failed. The block directory cleanup is skipped when the block was not downloaded (dir is empty).","triggerScenarios":"removeBlock is called during block sync for a block no longer present in the bucket, and BucketBlock.Close returns an error closing the index reader, chunk reader, or on-disk directory.","commonSituations":"File-descriptor exhaustion preventing readers from closing cleanly, temp-dir on a failing/unmounted disk preventing directory removal, blocks evicted during shutdown while queries still hold readers.","solutions":["Check the wrapped root error: if it is a directory-removal failure, verify the cache/temp directory is writable and mounted.","Check for file-descriptor or memory pressure that breaks reader Close paths; raise limits or reduce max concurrency.","Restart the store gateway after the transient condition clears; Close failures are rarely actionable in-process."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := store.RemoveBlock(ctx, id); err != nil && strings.Contains(err.Error(), \"close block\") {\n\tlogger.Warn(\"non-fatal block close failure, will retry next sync\", \"err\", err)\n} else if err != nil {\n\treturn err\n}","preventionTips":["Raise file-descriptor limits (ulimit) on store gateways.","Monitor temp/cache directory disk health and free space.","Allow graceful shutdown periods so in-flight readers can be closed cleanly."],"tags":["resource-cleanup","thanos-store","block-sync"],"backgroundTag":"resource-cleanup-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"}