fix: make CH pause/resume idempotent via error matching (no extra vm.info)#52
Merged
Conversation
CH's Vm::pause / Vm::resume at vmm/src/vm.rs:412-440 reject same-state transitions (Paused→Paused, Running→Running) as InvalidStateTransition, returning 500. A cocoon process SIGKILLed between pause and resume during snapshot save leaves the VM stuck Paused, after which every subsequent snapshot save fails — observed on GKE prod and journal-confirmed. pauseVM / resumeVM now swallow CH's exact "Invalid transition: InvalidStateTransition(<state>, <state>)" 500 body, treating it as "already in the desired state". Matched via APIError code + substring; transport errors, other 500 bodies, and different transitions (Created→Paused etc.) still propagate. FC research (upstream src/vmm/src/vstate/vcpu.rs): FC's vCPU event loop acks Pause from paused state and Resume from running state without error — FC API is inherently idempotent. Updated the misleading "Non-idempotent" comment on FC's pauseVM/resumeVM; no behavior change.
There was a problem hiding this comment.
Pull request overview
Makes Cloud Hypervisor pauseVM / resumeVM idempotent by detecting and swallowing CH's InvalidStateTransition(<state>, <state>) 500 response, so a stuck-Paused VM (e.g., after a SIGKILL mid-snapshot) can recover without an extra vm.info round trip. Also corrects an inaccurate "Non-idempotent" comment on the Firecracker pause/resume helpers, since FC's vCPU event loop already acks redundant transitions.
Changes:
- Add
isAlreadyInStateErrorhelper matching CH's exact 500 body viautils.APIError.Code+strings.Contains, and use it inpauseVM/resumeVM. - New
TestIsAlreadyInStateErrorcovering 9 cases (matches, wrong state, non-500, non-APIError, nil, wrapped error, empty state, etc.). - Update Firecracker
pauseVM/resumeVMdoc comments to reflect that FC's pause/resume is inherently idempotent.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| hypervisor/cloudhypervisor/helper.go | Adds error-matching helper and wires it into pauseVM/resumeVM to swallow same-state transitions. |
| hypervisor/cloudhypervisor/helper_test.go | New unit tests for isAlreadyInStateError. |
| hypervisor/firecracker/api.go | Corrects misleading "Non-idempotent" doc comments on FC pause/resume. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Vm::pause/Vm::resumereject same-state transitions (vmm/src/vm.rs:412-440) — a cocoon process SIGKILLed mid-snapshot leaves the VM stuckPaused, after which every subsequentsnapshot savefails with500 InvalidStateTransition(Paused, Paused). This was the root cause of the journal noise that helped trigger fix: kill orphan VMM via /proc cmdline fallback when pidfile pre-removed #51's orphan chain on GKE prod.pauseVM/resumeVMswallow CH's exactInvalid transition: InvalidStateTransition(<state>, <state>)500 body viaAPIError.Code+strings.Containson the message. No extravm.inforound-trip.src/vmm/src/vstate/vcpu.rsackPausefrompaused()andResumefromrunning()without error). The "Non-idempotent" comment infirecracker/api.gowas wrong — comment-only cleanup.Repro (testbed)
Test plan
make lint0 issues, bothGOOS=linuxandGOOS=darwinTestIsAlreadyInStateError(9 cases: paused/running match, wrong-state, non-500, different-transition, non-APIError, nil, wrapped viafmt.Errorf %w, empty state)vm.pausevia curl →cocoon snapshot savesucceeds (was failing pre-fix); cleanup leaves no orphanInvalidStateTransition(Paused, Paused)recurrence after next e2e batch