{"record":{"id":"395b948eaa15bdd7","repo":"hashicorp/packer","slug":"failed-to-update-hcp-packer-build-status-for-q","errorCode":null,"errorMessage":"failed to update HCP Packer Build status for %q: %s","messagePattern":"failed to update HCP Packer Build status for %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/hcp/registry/types.bucket.go","lineNumber":679,"sourceCode":"\t\t}\n\n\t\tlog.Printf(\"[TRACE] stopped heartbeating build %s\", build)\n\t}()\n\treturn func() {\n\t\tclose(heartbeatChan)\n\t}, nil\n}\n\nfunc (bucket *Bucket) startBuild(ctx context.Context, buildName string) error {\n\tif !bucket.IsExpectingBuildForComponent(buildName) {\n\t\treturn &ErrBuildAlreadyDone{\n\t\t\tMessage: \"build is already done\",\n\t\t}\n\t}\n\n\terr := bucket.UpdateBuildStatus(ctx, buildName, hcpPackerModels.HashicorpCloudPacker20230101BuildStatusBUILDRUNNING)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to update HCP Packer Build status for %q: %s\", buildName, err)\n\t}\n\n\tcleanupHeartbeat, err := bucket.HeartbeatBuild(ctx, buildName)\n\tif err != nil {\n\t\tlog.Printf(\"[ERROR] failed to start heartbeat function\")\n\t}\n\n\tbuildDone := make(chan struct{}, 1)\n\tgo func() {\n\t\tlog.Printf(\"[TRACE] waiting for heartbeat completion\")\n\t\tselect {\n\t\tcase <-ctx.Done():\n\t\t\tcleanupHeartbeat()\n\t\t\terr := bucket.UpdateBuildStatus(\n\t\t\t\tcontext.Background(),\n\t\t\t\tbuildName,\n\t\t\t\thcpPackerModels.HashicorpCloudPacker20230101BuildStatusBUILDCANCELLED)\n\t\t\tif err != nil {","sourceCodeStart":661,"sourceCodeEnd":697,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/internal/hcp/registry/types.bucket.go#L661-L697","documentation":"startBuild marks the build as BUILDRUNNING in HCP Packer before any provisioning starts, so registry consumers see it in progress. If bucket.UpdateBuildStatus fails (API error, stale RunUUID, cancelled context), the build cannot be tracked and Packer aborts the build with this wrapped error.","triggerScenarios":"Bucket.StartBuild -> startBuild calls UpdateBuildStatus(ctx, buildName, BUILDRUNNING) and the underlying UpdateBuild API call fails — network errors, invalid/expired RunUUID mismatch (another Packer run owns the build), 4xx/5xx responses, or the passed ctx is already cancelled.","commonSituations":"Two concurrent Packer runs using the same bucket+fingerprint (second run's RunUUID rejected); expired HCP credentials mid-run; HCP Packer service incident; cancelled context from Ctrl-C or CI timeout right at build start.","solutions":["Ensure only one Packer run targets the same bucket/fingerprint at a time; use distinct fingerprints for parallel runs","Re-authenticate / refresh HCP credentials and retry the build","Check the inner error for HTTP status; if 5xx, retry after confirming HCP Packer service health","If a ctx cancellation caused it, re-run the build without immediately cancelling"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Serialize runs that share a bucket/fingerprint before starting Packer\n// if !flock(\"/tmp/packer-<bucket>-<fingerprint>.lock\") { exit \"another run is active\" }\n// test -n \"$HCP_CLIENT_ID\" && test -n \"$HCP_CLIENT_SECRET\" || exit 1","typeGuard":null,"tryCatchPattern":"// Go\nif err := bucket.StartBuild(ctx, buildName); err != nil {\n\tif strings.Contains(err.Error(), \"failed to update HCP Packer Build status\") {\n\t\t// status update failed: check RunUUID ownership, credentials, and service health,\n\t\t// then retry once with a fresh context\n\t\treturn retryWithFreshCtx(ctx, bucket.StartBuild, buildName)\n\t}\n\treturn err\n}","preventionTips":["Never run two Packer builds concurrently against the same bucket+fingerprint","Handle SIGINT/CI cancellation gracefully so contexts aren't dead at build start","Refresh long-lived HCP credentials; keep builds under token TTL","Use distinct buckets or fingerprints for parallel CI jobs"],"tags":["hcp-packer","build-status","api-call","concurrency"],"backgroundTag":"build-status-update-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"}