{"record":{"id":"e886c8a871dc90fd","repo":"kopia/kopia","slug":"error-writing-index-blob-e886c8","errorCode":null,"errorMessage":"error writing index blob","messagePattern":"error writing index blob","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"repo/content/content_manager.go","lineNumber":483,"sourceCode":"\t\tdataShards, closeShards, err := bm.packIndexBuilder.BuildShards(mp.IndexVersion, true, indexblob.DefaultIndexShardSize)\n\n\t\tspan2.End()\n\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"unable to build pack index\")\n\t\t}\n\n\t\tdefer closeShards()\n\n\t\t// we must hold a lock between writing an index and adding index blob to committed contents index\n\t\t// otherwise it is possible for concurrent compaction or refresh to forget about the blob we have just\n\t\t// written\n\t\tbm.indexesLock.RLock()\n\t\tdefer bm.indexesLock.RUnlock()\n\n\t\tindexBlobMDs, err := bm.writeIndexBlobs(ctx, dataShards, bm.currentSessionInfo.ID)\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"error writing index blob\")\n\t\t}\n\n\t\tif err := bm.commitSession(ctx); err != nil {\n\t\t\treturn errors.Wrap(err, \"unable to commit session\")\n\t\t}\n\n\t\t// if we managed to commit the session marker blobs, the index is now fully committed\n\t\t// and will be visible to others, including blob GC.\n\n\t\tfor i, indexBlobMD := range indexBlobMDs {\n\t\t\tbm.onUpload(int64(dataShards[i].Length()))\n\n\t\t\tif err := bm.addIndexBlob(ctx, indexBlobMD.BlobID, dataShards[i], true); err != nil {\n\t\t\t\treturn errors.Wrap(err, \"unable to add committed content\")\n\t\t\t}\n\t\t}\n\n\t\tbm.packIndexBuilder = make(index.Builder)","sourceCodeStart":465,"sourceCodeEnd":501,"githubUrl":"https://github.com/kopia/kopia/blob/82495e54b584c1ef6073c9e1be048f57f8aef078/repo/content/content_manager.go#L465-L501","documentation":"After index shards are built, flushPackIndexesLocked uploads them to storage via writeIndexBlobs, associating them with the current session ID. This error wraps a failure of that upload — the index blob(s) could not be written to the underlying blob storage. The session is not committed, so the new index entries are not yet visible to other clients, and Flush() fails.","triggerScenarios":"Calling Flush (explicitly or via auto-flush/Close) while writeIndexBlobs fails — blob-storage upload errors such as network outage, expired cloud credentials, bucket permissions changed to read-only, or provider 5xx/throttling errors.","commonSituations":"Cloud storage credential expiry during long backup sessions; loss of connectivity to S3/GCS/Azure/BLOB endpoints; storage quota exceeded; accidental bucket policy change revoking write access mid-run.","solutions":["Check the wrapped cause for the underlying provider error and HTTP status","Verify and refresh storage credentials; confirm the bucket still allows writes","Retry Flush after connectivity is restored — index writes are idempotent per session","Test storage with a direct upload (e.g. aws s3 cp) to isolate the backend","Check rate-limit responses and add backoff/retry configuration to the storage provider"],"exampleFix":"// before\nrepo.Flush(ctx) // fails silently into generic handler\n// after\nerr := repo.Flush(ctx)\nif err != nil && strings.Contains(err.Error(), \"error writing index blob\") {\n\trefreshStorageCredentials()\n\ttime.Sleep(5 * time.Second)\n\terr = repo.Flush(ctx)\n}","handlingStrategy":"retry","validationCode":"// Go: confirm bucket is writable before flushing index blobs\nif err := probeBlobWrite(ctx, storage); err != nil {\n\treturn fmt.Errorf(\"cannot write index blob: storage not writable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"err := repo.Flush(ctx)\nif err != nil && strings.Contains(err.Error(), \"error writing index blob\") {\n\ttime.Sleep(retryDelay) // transient storage error\n\terr = repo.Flush(ctx)\n}","preventionTips":["Ensure credentials include write permissions for the entire session","Check bucket policy/IAM changes before long runs","Add exponential backoff at the storage provider layer","Alert on storage 5xx and throttling during backups"],"tags":["index-blob","storage-upload","flush","blob-storage"],"backgroundTag":"file-write-failed","analyzedSha":"82495e54b584c1ef6073c9e1be048f57f8aef078","analyzedAt":"2026-09-07T20:35:21.689Z","contentChangedAt":"2026-09-07T20:35:21.689Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}