{"record":{"id":"41b5a4f742737410","repo":"kopia/kopia","slug":"error-writing-pack","errorCode":null,"errorMessage":"error writing pack","messagePattern":"error writing pack","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"repo/content/content_manager.go","lineNumber":562,"sourceCode":"\t// after finishing writing, remove from both writingPacks and failedPacks\n\tbm.writingPacks = removePendingPack(bm.writingPacks, pp)\n\tbm.failedPacks = removePendingPack(bm.failedPacks, pp)\n\n\tif writeErr == nil {\n\t\t// success, add pack index builder entries to index.\n\t\tfor _, info := range packFileIndex {\n\t\t\tbm.packIndexBuilder.Add(info)\n\t\t}\n\n\t\tpp.currentPackData.Close()\n\n\t\treturn nil\n\t}\n\n\t// failure - add to failedPacks slice again\n\tbm.failedPacks = append(bm.failedPacks, pp)\n\n\treturn errors.Wrap(writeErr, \"error writing pack\")\n}\n\nfunc (sm *SharedManager) prepareAndWritePackInternal(ctx context.Context, pp *pendingPackInfo, onUpload func(int64)) (index.Builder, error) {\n\tctx = contentlog.WithParams(ctx,\n\t\tlogparam.String(\"span:writePack\", string(pp.packBlobID)))\n\n\tmp, mperr := sm.format.GetMutableParameters(ctx)\n\tif mperr != nil {\n\t\treturn nil, errors.Wrap(mperr, \"mutable parameters\")\n\t}\n\n\tpackFileIndex, err := sm.preparePackDataContent(ctx, mp, pp)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"error preparing data content\")\n\t}\n\n\tif pp.currentPackData.Length() > 0 {\n\t\tif err := sm.writePackFileNotLocked(ctx, pp.packBlobID, pp.currentPackData.Bytes(), onUpload); err != nil {","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/kopia/kopia/blob/82495e54b584c1ef6073c9e1be048f57f8aef078/repo/content/content_manager.go#L544-L580","documentation":"Returned by processWritePackResultLocked when an asynchronously written pack fails. The pending pack is moved back to failedPacks so a later Flush retries it; this error reports the writeErr from the background pack writer to the caller of writePackAndAddToIndexUnlocked/Locked.","triggerScenarios":"writePackAndAddToIndexUnlocked detects pp.err set by the async writePackAndAddToIndexUnlocked goroutine (or the synchronous path fails); any error preparing or uploading the pack data blob surfaces here wrapped as 'error writing pack'.","commonSituations":"Background pack writer hit a transient storage failure (connection reset, throttling by S3); the context was canceled while the pack write was in flight; the pack blob failed integrity checks after upload.","solutions":["Read writeErr in the chain — it is the original storage/preparation error.","Call Flush() again; the pack was re-queued in failedPacks and will be retried.","Check network stability and storage provider throttling (S3 503 SlowDown, etc.); consider retry-able blob storage options.","If persistent, verify the storage backend is writable and not read-only (e.g. wrong bucket permissions, repository opened read-only by mistake)."],"exampleFix":"// before: assuming a failed pack write is fatal\nif err := bm.writePackAndAddToIndexUnlocked(ctx, pp); err != nil {\n    return err\n}\n// after: failed packs are retried by Flush; surface but allow recovery\nif err := bm.writePackAndAddToIndexUnlocked(ctx, pp); err != nil {\n    logger.Warnf(\"pack write failed (will retry on Flush): %v\", err)\n    if retryErr := bm.Flush(ctx); retryErr != nil {\n        return retryErr\n    }\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Go: failed packs are auto-requeued; retry via Flush\nif err := bm.Flush(ctx); err != nil {\n    return errors.Wrap(err, \"pack write failed; failed packs will be retried\")\n}","preventionTips":["Configure blob storage retry/timeout options for flaky networks","Handle provider throttling (S3 SlowDown) with backoff at the storage layer","Don't cancel the context while async pack writes are in flight","Call Flush before Close so failed packs get a retry"],"tags":["storage","pack","async","retry"],"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"}