{"record":{"id":"a29e1a89eb54be08","repo":"hashicorp/packer","slug":"failed-to-create-zstd-encoder-s","errorCode":null,"errorMessage":"failed to create zstd encoder: %s","messagePattern":"failed to create zstd encoder: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packer/provisioner.go","lineNumber":403,"sourceCode":"\tpackerSbom, err := os.Open(tmpFileName)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to open Packer SBOM file %q: %s\", tmpFileName, err)\n\t}\n\tdefer func() {\n\t\tif err := packerSbom.Close(); err != nil {\n\t\t\tlog.Printf(\"[WARN] Failed to close Packer SBOM file: %s\", err)\n\t\t}\n\t}()\n\n\tprovisionerOut := &hcpSbomProvisioner.PackerSBOM{}\n\terr = json.NewDecoder(packerSbom).Decode(provisionerOut)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"malformed packer SBOM output from file %q: %s\", tmpFileName, err)\n\t}\n\n\tencoder, err := zstd.NewWriter(nil, zstd.WithEncoderLevel(zstd.SpeedBestCompression))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create zstd encoder: %s\", err)\n\t}\n\tp.CompressedData = encoder.EncodeAll(provisionerOut.RawSBOM, nil)\n\tp.SBOMFormat = provisionerOut.Format\n\tp.SBOMName = provisionerOut.Name\n\n\treturn nil\n}\n","sourceCodeStart":385,"sourceCodeEnd":411,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/packer/provisioner.go#L385-L411","documentation":"Thrown when initializing the klauspost/compression zstd encoder fails. This is rare — zstd.NewWriter with only an encoder-level option essentially never fails unless memory for the encoder cannot be allocated.","triggerScenarios":"Provision calls zstd.NewWriter(nil, zstd.WithEncoderLevel(zstd.SpeedBestCompression)) and it returns an error, which only realistically happens on allocation failure (severe memory pressure / cgroup OOM limits).","commonSituations":"Containers with very low memory limits; hosts under extreme memory exhaustion while compressing a large SBOM.","solutions":["Increase the memory available to the Packer process/container and retry","Lower the compression level by patching/using a Packer build without SpeedBestCompression if you build from source","Check dmesg/OOM-killer logs to confirm memory pressure caused the failure"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Go: ensure the process has headroom before heavy compression\nvar ms runtime.MemStats\nruntime.ReadMemStats(&ms)\n// e.g. require at least 128 MiB heap headroom in constrained containers\nif ms.Sys > 4<<30 { log.Println(\"memory pressure: expect slow zstd best-compression\") }","typeGuard":null,"tryCatchPattern":"if err := p.Provision(ctx, ui, comm, data); err != nil {\n    if strings.Contains(err.Error(), \"failed to create zstd encoder\") {\n        // raise container memory limit and retry\n    }\n    return err\n}","preventionTips":["Give Packer containers/memory cgroups adequate RAM (512 MiB+)","Watch for OOM-killer events in dmesg during builds","Retry once — allocation failures are often transient"],"tags":["go","zstd","memory","compression"],"backgroundTag":"resource-allocation-failed","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}