{"record":{"id":"f255e6b2fc0fdacf","repo":"thanos-io/thanos","slug":"sync-block","errorCode":null,"errorMessage":"sync block","messagePattern":"sync block","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/bucket.go","lineNumber":798,"sourceCode":"\n\t// Sync advertise labels.\n\ts.mtx.Lock()\n\ts.advLabelSets = make([]labelpb.ZLabelSet, 0, len(s.advLabelSets))\n\tfor _, bs := range s.blockSets {\n\t\ts.advLabelSets = append(s.advLabelSets, labelpb.ZLabelSet{Labels: labelpb.ZLabelsFromPromLabels(bs.labels.Copy())})\n\t}\n\tsort.Slice(s.advLabelSets, func(i, j int) bool {\n\t\treturn strings.Compare(s.advLabelSets[i].String(), s.advLabelSets[j].String()) < 0\n\t})\n\ts.mtx.Unlock()\n\treturn nil\n}\n\n// InitialSync perform blocking sync with extra step at the end to delete locally saved blocks that are no longer\n// present in the bucket. The mismatch of these can only happen between restarts, so we can do that only once per startup.\nfunc (s *BucketStore) InitialSync(ctx context.Context) error {\n\tif err := s.SyncBlocks(ctx); err != nil {\n\t\treturn errors.Wrap(err, \"sync block\")\n\t}\n\n\tif s.dir == \"\" {\n\t\treturn nil\n\t}\n\n\tfis, err := os.ReadDir(s.dir)\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"read dir\")\n\t}\n\tnames := make([]string, 0, len(fis))\n\tfor _, fi := range fis {\n\t\tnames = append(names, fi.Name())\n\t}\n\tfor _, n := range names {\n\t\tid, ok := block.IsBlockDir(n)\n\t\tif !ok {\n\t\t\tcontinue","sourceCodeStart":780,"sourceCodeEnd":816,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/store/bucket.go#L780-L816","documentation":"BucketStore.InitialSync wraps errors from SyncBlocks with \"sync block\". SyncBlocks iterates the object store bucket, downloads missing block metadata and syncs local state; any bucket access, metadata fetch, or block download failure surfaces wrapped as \"sync block: <cause>\".","triggerScenarios":"InitialSync (or background sync) hitting object storage failures: missing bucket permissions (s3:GetObject/ListBucket), network timeouts, invalid bucket credentials, or corrupt meta.json in a block.","commonSituations":"Store Gateway starting with wrong S3/GCS credentials, IAM policy missing list permissions, bucket region mismatch, object storage outage, or a partially-uploaded (failed) block in the bucket.","solutions":["Run `thanos tools bucket verify` to find corrupt/partially uploaded blocks.","Verify object store credentials and IAM permissions (ListBucket, GetObject on the bucket prefix).","Check network/proxy connectivity to the object storage endpoint from the pod.","Remove or repair blocks with invalid meta.json (marked for no-compact-mark / deletion)."],"exampleFix":"// before\nerr := store.InitialSync(ctx) // opaque \"sync block: ...\" failure\n// after\nerr := store.InitialSync(ctx)\nif err != nil {\n    logger.Error(\"initial block sync failed; check bucket credentials and corrupt blocks\", \"err\", err)\n    return err\n}","handlingStrategy":"retry","validationCode":"if err := checkBucketAccess(ctx, bkt); err != nil {\n    return errors.Wrap(err, \"bucket not accessible before InitialSync\")\n}","typeGuard":null,"tryCatchPattern":"err := store.InitialSync(ctx)\nif err != nil {\n    if isTransientStorageErr(err) {\n        return retryWithBackoff(ctx, store.InitialSync)\n    }\n    return errors.Wrap(err, \"initial sync failed permanently\")\n}","preventionTips":["Verify object-store credentials and IAM at startup","Run bucket verify to remove corrupt blocks","Add network egress checks for the storage endpoint"],"tags":["thanos","object-storage","sync"],"backgroundTag":"api-request-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"}