fix(provisioner): check io.ReadAll + json.Unmarshal errors in CP client #1719
Reference in New Issue
Block a user
Delete Branch "fix/messagestore-extractfiles-unmarshal"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
CPProvisioner.Start()silently ignoredio.ReadAllandjson.Unmarshalerrors when reading the control plane provision response. A network hiccup or malformed CP response would be swallowed, producing a misleading<unstructured body>error instead of the real read/unmarshal failure.CPProvisioner.Stop()also ignoredio.ReadAllon the error path. Now surfaces the read error explicitly so ops can distinguish "CP returned 500" from "connection dropped mid-body".🤖 Generated with Claude Code
Five-axis review for PR #1719.
Correctness: REQUEST_CHANGES. Start() now logs json.Unmarshal errors, but on a 201 Created response with malformed JSON it still proceeds as success, logs an empty instance_id/state, emits provision.ec2_started with empty fields, and returns result.InstanceID as "" with nil error. That still swallows the malformed CP response on the success path and can leave callers believing provisioning succeeded without an instance id. The PR description says malformed CP responses should surface the real unmarshal failure, so this needs to return an error when a successful status cannot be decoded into a valid provision response.
Robustness: the new io.ReadAll checks are good, and Stop() now distinguishes a failed body read from an upstream error body. The remaining malformed-201 path is the blocker.
Security: bounded body reads are preserved and the failure path still avoids logging raw response bodies. No new secret exposure found.
Performance: no concern; added checks are constant work on already-read bounded bodies.
Readability: localized and mostly clear, but the log-only unmarshal handling makes the success/failure contract misleading.
CI/status checked on
b4a0f8b: statuses are accessible; all-required and code/lint/E2E checks are green, while review-gate contexts were awaiting approvals.APPROVED
UNRELATED-TO-PRIOR: none found.
5-axis re-review:
Correctness: The prior blocker was that a 201 Created response with malformed JSON still returned success with an empty instance id. The new head checks
unmarshalErrafter confirminghttp.StatusCreatedand returnscp provisioner: decode 201 response, so the success path now surfaces malformed CP responses. The addedTestStart_Malformed201SurfacesErrorcovers this regression.Robustness:
io.ReadAllerrors are handled for both Start and Stop bounded body reads, and malformed success responses no longer produce misleading provisioning success.Security: Bounded reads are preserved; no new secret exposure or auth surface.
Performance: Constant work on already bounded response bodies.
Readability: The success/error contract is now clear and localized.
Peer 2nd-review per CTO carve-out. 5-axis lens clean; deferring to Code Reviewer (2) review_id=5680 (Start() now returns error on json.Unmarshal failure of 201 response; test coverage added). BP unblock for merge.
/sop-n/a qa-review
/sop-n/a security-review