fix(cubeapi): return 404 when deleting missing sandbox#759
Conversation
Review: fix(cubeapi): return 404 when deleting missing sandboxThis is a well-scoped, semantically correct change. The overall assessment across all dimensions is positive — the PR is ready to merge. Summary
What is done well
Findings worth addressing1. Potential bug: Sync path returns MasterInternalError instead of NotFound on race (sandbox_remove.go:101-106). If req.Sync is true and the sandbox is deleted between cache lookup and cubelet call, DestroySandbox wraps it as MasterInternalError regardless of what the cubelet returned. Pre-existing, but worth following up. 2. Test gap: sync path completely untested. Not even the success case has coverage. 3. Minor: sandbox_id dropped in non-not-found error messages (sandboxes.rs:632-633). Including it in the anyhow! message would improve debuggability. ConclusionWell-structured PR, ready to merge. Items 1 and 2 are follow-up candidates. |
|
LGTM |
| Sync: true, | ||
| }) | ||
|
|
||
| if got.Ret.RetCode != int(errorcode.ErrorCode_NotFound) { |
There was a problem hiding this comment.
We have testify in go.mod already, please use it for test cases.
adb79fc to
4152c0e
Compare
| case cubebox.InstanceType_cubebox.String(): | ||
| if !dealScfSandbox(ctx, req, t) { | ||
| rsp.Ret.RetCode = int(errorcode.ErrorCode_NotFound) | ||
| rsp.Ret.RetMsg = "no such sandbox" |
There was a problem hiding this comment.
Suggestion: Include the sandbox ID in the error message for better debuggability, consistent with the Rust side which always includes it:
rsp.Ret.RetMsg = "no such sandbox: " + req.SandboxID| RequestID: "req-missing-delete", | ||
| SandboxID: "sandbox-does-not-exist", | ||
| InstanceType: cubebox.InstanceType_cubebox.String(), | ||
| Sync: true, |
There was a problem hiding this comment.
Suggestion: The Sync: true field is unused here — the early return at line 99 fires before the sync path (line 101) is reached. Consider removing it or adding a comment explaining it is immaterial to avoid confusing future readers.
Return CubeMaster not found for missing sandbox deletes and map the CubeAPI delete path to AppError::NotFound. Signed-off-by: Han Zhang <ihanzhzh@gmail.com>
4152c0e to
c508fcd
Compare
Summary
Fixes #231.
This PR changes sandbox deletion behavior so deleting a nonexistent sandbox returns
404 Not Foundinstead of204 No Content.Previously, CubeMaster returned
"no such sandbox"without setting a non-success ret code, so CubeAPI treated the delete operation as successful. CubeMaster now returnsErrorCode_NotFound, and CubeAPI maps that CubeMaster not-found response toAppError::NotFound.Changes
ErrorCode_NotFoundfrom CubeMaster when deleting a missing sandbox.404 Not Found.Validation
CUBE_MASTER_CONFIG_PATH=/home/han/project/CubeSandbox/CubeMaster/conf.yaml GOCACHE=/tmp/cubesandbox-go-cache GOMODCACHE=/tmp/cubesandbox-go-mod-cache go test ./pkg/service/sandboxCARGO_HOME=/tmp/cubesandbox-cargo-home CARGO_TARGET_DIR=/tmp/cubesandbox-cubeapi-target cargo test --manifest-path CubeAPI/Cargo.toml services::sandboxes::tests::kill_sandbox_maps_cubemaster_not_found_to_app_not_foundScreenshots
Not applicable. This is an API behavior fix.