{"record":{"id":"12a47d71a35b357f","repo":"thanos-io/thanos","slug":"unable-to-open-tbc-directory","errorCode":null,"errorMessage":"unable to open tbc directory","messagePattern":"unable to open tbc directory","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/thanos/tools_bucket.go","lineNumber":1491,"sourceCode":"\t\t\treturn errors.Wrapf(err, \"unable to access path '%s'\", tbc.path)\n\t\t}\n\n\t\tconfContentYaml, err := objStoreConfig.Content()\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"unable to parse objstore config\")\n\t\t}\n\n\t\tbkt, err := client.NewBucket(logger, confContentYaml, component.Upload.String(), nil)\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"unable to create bucket\")\n\t\t}\n\n\t\tbkt = objstoretracing.WrapWithTraces(objstore.WrapWithMetrics(bkt, extprom.WrapRegistererWithPrefix(\"thanos_\", reg), bkt.Name()))\n\n\t\ttbcDir, err := os.OpenRoot(tbc.path)\n\t\tif err != nil {\n\t\t\trunutil.CloseWithLogOnErr(logger, bkt, \"bucket client\")\n\t\t\treturn errors.Wrap(err, \"unable to open tbc directory\")\n\t\t}\n\n\t\ts := shipper.New(\n\t\t\tbkt,\n\t\t\ttbcDir,\n\t\t\tshipper.WithLogger(logger),\n\t\t\tshipper.WithRegisterer(reg),\n\t\t\tshipper.WithSource(metadata.BucketUploadSource),\n\t\t\tshipper.WithMetaFileName(shipper.DefaultMetaFilename),\n\t\t\tshipper.WithLabels(func() labels.Labels { return lset }),\n\t\t\tshipper.WithUploadCompacted(tbc.uploadCompacted),\n\t\t\tshipper.WithUploadConcurrency(tbc.uploadConcurrency),\n\t\t)\n\n\t\tctx, cancel := context.WithCancel(context.Background())\n\t\tg.Add(func() error {\n\t\t\tdefer runutil.CloseWithLogOnErr(logger, bkt, \"bucket client\")\n\t\t\tdefer runutil.CloseWithLogOnErr(logger, tbcDir, \"tbc directory\")","sourceCodeStart":1473,"sourceCodeEnd":1509,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/cmd/thanos/tools_bucket.go#L1473-L1509","documentation":"This error is returned when os.OpenRoot(tbc.path) fails after the bucket client was successfully created. OpenRoot opens the local directory as a rooted filesystem handle used by the shipper; failure typically means the directory does not exist or is inaccessible at open time. The command closes the bucket client and aborts the upload.","triggerScenarios":"The --path directory was deleted or renamed between the earlier IsDirAccessible check and OpenRoot; permission changed; or (on older thanos versions using ioutil.TempDir-style open) the path is a file rather than a directory.","commonSituations":"Race with a cleanup job removing the data dir; running the command while a deployment remounts or rotates the volume; SELinux/AppArmor denying directory open despite stat succeeding; pointing at a symlink whose target was removed.","solutions":["Re-check that the --path directory still exists and is a readable directory at run time (ls -ld <path>)","Check for external processes (cleanup jobs, volume remounts) mutating the directory while the tool runs","Inspect audit logs (SELinux denials, auditd) if stat succeeds but open fails","Re-run the command once the directory is restored; earlier checks passed so the config itself is fine"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"info, err := os.Stat(path)\nif err != nil || !info.IsDir() {\n    return fmt.Errorf(\"directory %q must exist and be a directory before sync\", path)\n}","typeGuard":null,"tryCatchPattern":"if _, err := os.OpenRoot(path); err != nil {\n    logger.Error(err, \"cannot open data directory; check it still exists and is not being remounted\")\n    return err\n}","preventionTips":["Avoid running uploads while cleanup jobs or volume rotations touch the data directory","Use stable absolute paths, not volatile symlinks","Check audit/SELinux logs when stat succeeds but open fails","Re-run after transient failures; earlier stages (stat, config, bucket) already validated"],"tags":["go","filesystem","thanos"],"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"}