Repository navigation
[sled-agent-sim] add a way to interrupt VMM registration - #11606
Merged
Merged
Conversation
hawkw
force-pushed
the
eliza/vmm-registration-pause
branch
2 times, most recently
from
October 27, 2026 22:06
46659f7 to
daae088
Compare
jgallagher
approved these changes
Oct 29, 2026
jgallagher
left a comment
Contributor
There was a problem hiding this comment.
LGTM, just a few nits/questions.
| let (resume_tx, resume_rx) = oneshot::channel(); | ||
| // If the test has dropped its handle to pause this request, do | ||
| // nothing. | ||
| let _ = tx.send(PausedVmmRegistration { propolis_id, resume_tx }); |
Contributor
There was a problem hiding this comment.
If this send fails we'll definitely fall into the Err(_) branch below, right? Is that right or should we skip the resume_rx.await entirely if sending fails (either silently or with a different log message)?
| impl NextVmmRegistrationRequest { | ||
| /// Waits until a `vmm_register` request arrives and is paused, returning a | ||
| /// handle that controls when and how the request completes. | ||
| pub async fn wait_for_request(self) -> PausedVmmRegistration { |
Contributor
There was a problem hiding this comment.
Would we expect (correct) tests to always wrap this in a timeout? If so, should we take a timeout arg and do that ourselves to ensure it happens?
Member
Author
There was a problem hiding this comment.
Yeah, that's probably a good idea. The test I wrote using this in a subsequent branch was just wrapping this in a tokio::time::timeout, but we may as well make that part of the API.
This commit adds a new mechanism to the sled-agent simulator that allows a test to pause the next request to register a VMM (i.e. calls to `instance_ensure_registered` in the sled-agent API), wait until such a request is received by the simulator, and then explicitly decide when it may proceed. This is intended to allow writing a regression test for the issue described in #11560, where a race between requests to register an instance and to stop that instance results in Nexus seeing the VMM transition to `Failed` while the sled-agent continues starting it happily, leaking the Propolis zone.
Co-authored-by: John Gallagher <[email protected]>
hawkw
force-pushed
the
eliza/vmm-registration-pause
branch
from
October 29, 2026 16:11
0feeb57 to
6776a9d
Compare
Co-authored-by: John Gallagher <[email protected]>
hawkw
enabled auto-merge (squash)
October 29, 2026 16:12
hawkw
disabled auto-merge
October 29, 2026 16:45
hawkw
enabled auto-merge (squash)
October 29, 2026 16:46
hawkw
disabled auto-merge
October 29, 2026 16:46
hawkw
enabled auto-merge (squash)
October 29, 2026 16:46
hawkw
added a commit
that referenced
this pull request
Oct 29, 2026
hawkw
disabled auto-merge
October 29, 2026 17:20
hawkw
added a commit
that referenced
this pull request
Oct 29, 2026
Propolis zones for starting and migrating instances are ensured by the `sis_ensure_registered` and `sim_ensure_destination_propolis` actions in the `instance_start` and `instance_migrate` sagas, respectively. Currently, when the saga unwinds, these nodes' undo actions are responsible for ensuring the VMM they created are unregistered. There is a small issue here which is about to become much more important: the undo action of a node in an unwinding saga is only performed if the forward action has **succeeded**. This means that if the action that attempts to ensure the VMM begins executing and fails, unwinding the saga, the VMM it created is not unregistered. This is important because the `instance_ensure_registered` call in these nodes will send a request to the sled-agent to ensure the VMM is registered, *and then attempt to write the VMM state returned by the sled-agent to the database*. If the request is sent, but the database query fails, the node will fail, and the saga unwinds *without* unregistering the VMM. This will become more important in a subsequent PR where I will fix #11606 by making the `instance_ensure_registered` method actually check that it wrote the expected VMM state to the database and fail otherwise, but we may fail there for other reasons regardless. This branch fixes this by making these sagas attempt to unregister the Propolis zone if they made it as far as *starting* the undo action, regardless of its outcome. This is achieved by moving the undo action into a saga node that executes *before* the ensure node, with a no-op forward action. This way, if it's the ensure action that fails, we still clean up any Propolis zone we *may* have created.
hawkw
added a commit
that referenced
this pull request
Oct 29, 2026
hawkw
added a commit
that referenced
this pull request
Oct 29, 2026
hawkw
added a commit
that referenced
this pull request
Oct 29, 2026
Propolis zones for starting and migrating instances are ensured by the `sis_ensure_registered` and `sim_ensure_destination_propolis` actions in the `instance_start` and `instance_migrate` sagas, respectively. Currently, when the saga unwinds, these nodes' undo actions are responsible for ensuring the VMM they created are unregistered. There is a small issue here which is about to become much more important: the undo action of a node in an unwinding saga is only performed if the forward action has **succeeded**. This means that if the action that attempts to ensure the VMM begins executing and fails, unwinding the saga, the VMM it created is not unregistered. This is important because the `instance_ensure_registered` call in these nodes will send a request to the sled-agent to ensure the VMM is registered, *and then attempt to write the VMM state returned by the sled-agent to the database*. If the request is sent, but the database query fails, the node will fail, and the saga unwinds *without* unregistering the VMM. This will become more important in a subsequent PR where I will fix #11606 by making the `instance_ensure_registered` method actually check that it wrote the expected VMM state to the database and fail otherwise, but we may fail there for other reasons regardless. This branch fixes this by making these sagas attempt to unregister the Propolis zone if they made it as far as *starting* the undo action, regardless of its outcome. This is achieved by moving the undo action into a saga node that executes *before* the ensure node, with a no-op forward action. This way, if it's the ensure action that fails, we still clean up any Propolis zone we *may* have created.
hawkw
added a commit
that referenced
this pull request
Oct 29, 2026
hawkw
added a commit
that referenced
this pull request
Oct 30, 2026
Currently stacked atop #11606 as I want to use that to write a test for the thing I'm eventually aiming to fix here. Unwinding `instance_start` and `instance_migrate` sagas call the sled-agent `vmm_unregister` endpoint, in order to ensure that a Propolis zone that the unwinding saga may have created is destroyed. This is necessary because if we do not ensure any such zones that may have been created by a failed start or migration are removed, we may leak a running Propolis process that the control plane does not believe exists, and which cannot be stopped normally. While working on a fix for #11560, which involves changes to how `instance_start` sagas unwind, I noticed that the current code for ensuring a registered VMM is unregistered is a bit...sketchy. In particular: * The VMM is unregistered using the `Nexus::instance_ensure_unregistered` function. This looks up the sled-agent client, returns an error if no sled with that ID is found in the database, and then calls the `vmm_unregister` API through that client. If the `sled` record has been hard-deleted, the saga will get stuck (in [this branch][1]) * `Nexus::instance_ensure_unregistered` function wraps the response from the sled-agent in a `SledAgentInstanceError`. That error type is used to detect a 404 error with the `NO_SUCH_INSTANCE` error code, which some sled-agent endpoints use to indicate that a requested Propolis zone no longer exists, and the instance record should be marked as `Failed`. The `vmm_unregister` endpoint, however, **will never return that error code**: if the requested Propolis ID was never ensured, or has already been destroyed, [it just returns 200 OK][1]. If this were not the case, however, and it *did* return a 404 `NO_SUCH_INSTANCE` if the VMM didn't exist on the sled, we would be handling that error incorrectly: the `sis_ensure_registered_undo` undo action currently [attempts to mark the VMM as `Failed` and then returns an error][2]. This would be incorrect if it ever occurred, since we would have just been told that the VMM didn't exist on the sled (which is what we are trying to ensure), and we would have responded to it by **returning an error and getting the unwinding saga stuck**. Instead of doing that, the correct behavior would be to just keep unwinding in that case. * Any **other** error communicating with the sled-agent [is taken to mean that the VMM no longer exists][3]. This is incorrect: if we encountered a network error or a transient "channel full" from the sled-agent, we would just assume the VMM is gone and continue unwinding, potentially leaving behind a running Propolis zone. * The sled the VMM was on being expunged is not considered as a possibility by any of this code. Instead of this, the correct behavior for ensuring a Propolis zone is unregistered in an unwinding saga should be to retry indefinitely until we either receive a 200 OK from the sled-agent (indicating the VMM was either successfully destroyed or no longer existed), or until the sled itself is no longer in service (and we can treat any VMMs that may have been there as though they no longer existed). This commit changes the unwinding actions to do this by adding a new `ensure_vmm_unregistered` helper function in `sagas::instance_common` that uses a `progenitor_extras` `retry_operation_while_indefinitely` loop to continually retry calling the sled-agent's `vmm_unregister` endpoint until it returns a 200 OK or the `sagas::sled_out_of_service_gone_check` function indicates the sled is no longer in service. If the attempt to look up the sled-agent client in the database indicates that no record for that sled exists, we treat that as equivalent to the sled having been expunged, rather than letting the saga get stuck. Finally, I've removed the `Nexus::instance_ensure_unregistered` function and its wrapping of the error in `SledAgentInstanceError`, in favor of just calling the sled-agent client's `vmm_unregister` method directly. This way, we no longer have to handle the 404 `NO_SUCH_INSTANCE` error here at all, because the sled-agent will not return it in this case. [1]: https://github.com/oxidecomputer/omicron/blob/271efb284d43402110f79d0d6d842a351889ad34/nexus/src/app/sagas/instance_start.rs#L1032-L1040 [2]: https://github.com/oxidecomputer/omicron/blob/271efb284d43402110f79d0d6d842a351889ad34/sled-agent/src/instance_manager.rs#L270-L277 [3]: https://github.com/oxidecomputer/omicron/blob/271efb284d43402110f79d0d6d842a351889ad34/nexus/src/app/sagas/instance_start.rs#L994-L1022 [4]: https://github.com/oxidecomputer/omicron/blob/271efb284d43402110f79d0d6d842a351889ad34/nexus/src/app/sagas/instance_start.rs#L1024-L1029
hawkw
added a commit
that referenced
this pull request
Oct 30, 2026
hawkw
added a commit
that referenced
this pull request
Oct 30, 2026
hawkw
added a commit
that referenced
this pull request
Oct 30, 2026
This commit generalizes the `pause_next_vmm_registration` API that I added to the sled-agent simulator in #11606 so that it can also be used to pause `vmm_put_state` and `vmm_get_state` requests to the sled-agent. This allows a test to wait for a request is received by the sled-agent and do other things (such as running sagas or background tasks, making assertions, and so on...) before resuming it or injecting an error. It factors out most of the machinery added in #11606 into a generalized `VmmRequestPauseQueue`, and adds such a queue for the `vmm_put_state` and `vmm_get_state` endpoints. This obsoletes the previous `set_instance_ensure_state_error` API on the simulated sled-agent, which allowed setting an error that would be returned to `vmm_put_state` requests. The pause API can be used to inject errors similarly to that API, but allows more granular control. It lets the test wait for a request to be received, and can be used to inject an error into exactly one request, rather than "all requests while a flag is set". Therefore, I removed the old API in favor of this one, and updated the tests that were previously using it. I wanted this to enable writing additional tests for changes to the `instance-start` saga I'm working on. In addition, while making this change, I noticed that the preexisting integration test `test_instances_are_not_marked_failed_on_other_sled_agent_errors_by_instance_watcher` (which I wrote, naturally) was also a bit wrong. It was using the `set_instance_ensure_state_error` sled-agent-sim API, which only sets an error for the `vmm_put_state` endpoint, and **not** the `vmm_get_state` endpoint that instance-watcher uses. So, the injected error was not actually being seen by the instance-watcher in that test. By replacing the use of the old API, this branch also fixes that test.
hawkw
added a commit
that referenced
this pull request
Nov 3, 2026
…way (#11608) This branch fixes #11560, a race condition which occurs when an instance is requested to stop through the external API while an `instance_start` saga for that instance is in progress. The race occurs when the stop request is received while the VMM record is `Creating`, and is forwarded to the sled-agent. The `Creating` state represents a VMM where we have allocated a sled to run the instance and created a VMM record for the Propolis process we intend to start, but have not yet sent a `vmm_ensure` request to the sled-agent. When the sled-agent receives the request to stop the VMM, it has not yet received an ensure request to *create* that VMM, and therefore (correctly) indicates that it does not exist, which results in Nexus moving the VMM to `Failed` and kicking off an `instance_update` saga to transition the instance to `Failed` and delete the `vmm` record. However, this is invisible to the start saga, which continues its attempt to register and run the VMM, rather than unwinding. This ultimately results in the sled-agent running a VMM that the control plane considers dead. The control plane may then attempt to restart the instance elsewhere, which gets stuck when the new VMM tries to activate the same crucible disk(s) that the zombie VMM is already using. This branch closes the race by having the `Nexus::instance_ensure_registered` method read back the database record for the VMM to ensure that it successfully advanced the state to `Starting` after sending the `vmm_ensure` request to the sled-agent. I've included a test reproducing the race, which uses the new test utilities I added in #11606, to temporarily interrupt the sled-agent simulator and advance the VMM to `Failed` before responding to the `vmm_ensure` request. Prior to this change, the start saga continues, now it unwinds correctly. In my opinion, the behavior of forwarding requests to the sled-agent when a VMM is in the `Creating` state *remains wrong*. We allow a user to "cancel" starting an instance when it is in the `Starting` state, and the `Creating` VMM state maps to the `Starting` instance state in the external API. Therefore, we shouldn't just change the API to reject requests to stop an instance with a `Creating` VMM: I really want to avoid leaking the fact that some external-API states may represent multiple internal states, and therefore really dislike having `Starting` _sometimes_ let you stop the instance but other times not let you. Now that we fixed the race, the current behavior _does_ do more or less the correct thing, it just does it in a kind of awful *way*. When the VMM has not yet been started on the sled, we shouldn't send a request to the sled to stop it and rely on the fact that the sled-agent will mark it as failed to unwind the start saga. But, this PR doesn't change any of that; it just fixes the *dangerous consequences* of this behavior. Subsequently, we may want to change how instances are stopped when the VMM is in the `Creating` state. I'd prefer to do that in a separate change. Fixes #11560.
hawkw
added a commit
that referenced
this pull request
Nov 3, 2026
This commit generalizes the `pause_next_vmm_registration` API that I added to the sled-agent simulator in #11606 so that it can also be used to pause `vmm_put_state` and `vmm_get_state` requests to the sled-agent. This allows a test to wait for a request is received by the sled-agent and do other things (such as running sagas or background tasks, making assertions, and so on...) before resuming it or injecting an error. It factors out most of the machinery added in #11606 into a generalized `VmmRequestPauseQueue`, and adds such a queue for the `vmm_put_state` and `vmm_get_state` endpoints. This obsoletes the previous `set_instance_ensure_state_error` API on the simulated sled-agent, which allowed setting an error that would be returned to `vmm_put_state` requests. The pause API can be used to inject errors similarly to that API, but allows more granular control. It lets the test wait for a request to be received, and can be used to inject an error into exactly one request, rather than "all requests while a flag is set". Therefore, I removed the old API in favor of this one, and updated the tests that were previously using it. I wanted this to enable writing additional tests for changes to the `instance-start` saga I'm working on. In addition, while making this change, I noticed that the preexisting integration test `test_instances_are_not_marked_failed_on_other_sled_agent_errors_by_instance_watcher` (which I wrote, naturally) was also a bit wrong. It was using the `set_instance_ensure_state_error` sled-agent-sim API, which only sets an error for the `vmm_put_state` endpoint, and **not** the `vmm_get_state` endpoint that instance-watcher uses. So, the injected error was not actually being seen by the instance-watcher in that test. By replacing the use of the old API, this branch also fixes that test.
hawkw
added a commit
that referenced
this pull request
Nov 3, 2026
…ter` (#11643) This commit generalizes the `pause_next_vmm_registration` API that I added to the sled-agent simulator in #11606 so that it can also be used to pause `vmm_put_state` and `vmm_get_state` requests to the sled-agent. This allows a test to wait for a request is received by the sled-agent and do other things (such as running sagas or background tasks, making assertions, and so on...) before resuming it or injecting an error. It factors out most of the machinery added in #11606 into a generalized `VmmRequestPauseQueue`, and adds such a queue for the `vmm_put_state` and `vmm_get_state` endpoints. This obsoletes the previous `set_instance_ensure_state_error` API on the simulated sled-agent, which allowed setting an error that would be returned to `vmm_put_state` requests. The pause API can be used to inject errors similarly to that API, but allows more granular control. It lets the test wait for a request to be received, and can be used to inject an error into exactly one request, rather than "all requests while a flag is set". Therefore, I removed the old API in favor of this one, and updated the tests that were previously using it. I wanted this to enable writing additional tests for changes to the `instance-start` saga I'm working on. In addition, while making this change, I noticed that the preexisting integration test `test_instances_are_not_marked_failed_on_other_sled_agent_errors_by_instance_watcher` (which I wrote, naturally) was also a bit wrong. It was using the `set_instance_ensure_state_error` sled-agent-sim API, which only sets an error for the `vmm_put_state` endpoint, and **not** the `vmm_get_state` endpoint that instance-watcher uses. So, the injected error was not actually being seen by the instance-watcher in that test. By replacing the use of the old API, this branch also fixes that test.
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.
This commit adds a new mechanism to the sled-agent simulator that allows a test to pause the next request to register a VMM (i.e. calls to
instance_ensure_registeredin the sled-agent API), wait until such a request is received by the simulator, and then explicitly decide when it may proceed. This is intended to allow writing a regression test for the issue described in #11560, where a race between requests to register an instance and to stop that instance results in Nexus seeing the VMM transition toFailedwhile the sled-agent continues starting it happily, leaking the Propolis zone.