Repository navigation
[sled-agent] VMM graceful shutdown timeout - #7548
Conversation
smklein
left a comment
There was a problem hiding this comment.
Looks good to me, but as you said on the hypervisor channel, it would be nice to get a test for this before merging, if we can. This seems like the sorta feature that's nice-to-have, but which can break easily.
| // Only start the stop timeout if there | ||
| // isn't one already, so that additional | ||
| // requests to stop coming in don't reset | ||
| // the clock. |
There was a problem hiding this comment.
It does seem that we'd call put_state again in this case though -- is that desirable?
(a valid answer may be: "Sure!" - I'm just confirming)
There was a problem hiding this comment.
🤷♀️ we would call it twice before this change, so I didn't mess with it. I don't see any obvious reason why it would be bad to do it again, and maybe it's useful for e.g. a higher-level component retrying?
There was a problem hiding this comment.
FWIW my general philosophy here has been to have sled agent pass all state change requests right through to Propolis and let Propolis decide how to deal with any duplicates. (In this case it should just decide the second stop request can be ignored because it's already put one on its queue.)
There was a problem hiding this comment.
Yeah, that makes sense to me. I thought not resetting the timeout was worthwhile, though: you can imagine a scenario where an instance fails to stop, and a frustrated user or retrying client keeps sending more stop requests, each of which resets the grace period and stops the stuck VMM from being killed.
There was a problem hiding this comment.
Oh, I definitely agree--once the sled agent finds out about the control plane's intent to stop the instance, it should arm the timer and not reset it if the same intent is expressed again. Mostly I just wanted to provide a bit of color about calling Propolis twice; the Propolis state machine is designed to handle that kind of thing precisely so that sled agent doesn't have to worry about it.
There was a problem hiding this comment.
Yup, thanks for that! I figured we were on the same page about the timer but felt like it was worth clarifying further.
Yeah — this is mostly intended to protect against bugs in other components. So, in an ideal world, it's not going to be exercised that much unless we have a test for it. |
gjcolombo
left a comment
There was a problem hiding this comment.
Thanks for putting this together!
| // Only start the stop timeout if there | ||
| // isn't one already, so that additional | ||
| // requests to stop coming in don't reset | ||
| // the clock. |
There was a problem hiding this comment.
FWIW my general philosophy here has been to have sled agent pass all state change requests right through to Propolis and let Propolis decide how to deal with any duplicates. (In this case it should just decide the second stop request can be ignored because it's already put one on its queue.)
Presently, sled-agent's `InstanceRunner` has two mechanisms for shutting down a VMM: sending an instance state PUT request to the `propolis-server` process for the `Stopped` state, or forcibly terminating the `propolis-server` and tearing down the zone. At present, when a request to stop an instance is sent to the sled-agent, it uses the first mechanism, where Propolis is politely asked to stop the instance --- which I'll refer to as "graceful shutdown". The forceful termination path is used when asked to unregister an instance where the VMM has not started up yet, when encountering an unrecoverable VMM error, or when killing an instance that was making use of an expunged disk. Currently, these two paths don't really overlap: when Nexus asks a sled-agent to stop an instance, all it will do is politely ask Propolis to please stop the instance gracefully, and will only fall back to violently shooting the zone in the face if Propolis returns the error that indicates it never knew about that instance in the first place. This means that, should a VMM get *stuck* while shutting down the instance, stopping it will never complete successfully, and the Propolis zone won't get cleaned up. This can happen due to e.g. [a Crucible activation that will never complete][1]. Thus, the sled-agent should attempt to violently terminate a Propolis zone when a graceful shutdown of the VMM fails to complete in a timely manner. This commit introduces a timeout for the graceful shutdown process. Now, when we send a PUT request to Propolis with the `Stopped` instance state, the sled-agent will start a 10-minute timer. If no update from Propolis that indicates the instance has transitioned to `Stopped` is received before the timer completes, the sled-agent will proceed with the forceful termination of the Propolis zone. Fixes #4004. [1]: #4004 (comment)
This depends on oxidecomputer/propolis#869
3e536d9 to
452dda0
Compare
|
Okay, I've added a test for this which I'm pretty satisfied with. This depends on my Propolis PR oxidecomputer/propolis#869, which adds the ability to single-step the mock server's instance state machine. This is necessary to simulate a scenario in which Propolis gets stuck while shutting down. If @smklein or @gjcolombo are interested in reviewing the test, be my guest --- but I'm going to leave this PR in draft until the Propolis PR merges so that we can point our Git dep at propolis |
For certain test scenarios, the `propolis-mock-server` ought to have a mechanism for manual control of the mocked instance's progress through the state machine. In particular, this is necessary for testing changes like oxidecomputer/omicron#7548, which adds a timeout tracked by the sled-agent when an instance is stopped. If Propolis is stuck and cannot progress, the sled-agent will forcefully terminate it after that timeout...but testing this requires a way to make the mock Propolis pretend to be stuck. This commit adds the following new endpoints to the mock server which are not part of the real `propolis-server` API: - `PUT /mock/mode`: sets a mock mode, either `Run` (the normal behavior), or `SingleStep`, where state transitions only ocur when asked for by the test. - `GET /mock/mode`: returns whether or not we are single-steppy - `PUT /mock/step`: advances to the next queued generation Testing: I've written [a test in Omicron][1] that uses this, and I can make the mock propolis get wedged in the correct place. So that's nice. Closes #858 [1]: https://github.com/oxidecomputer/omicron/compare/eliza/single-steppy?expand=1
this changes the git dep to oxidecomputer/propolis@2652487
|
Okay, as we are now depending on the mock-server from oxidecomputer/propolis@2652487 (the |
Co-authored-by: Greg Colombo <[email protected]>
|
I'm guessing this |
Looks like sled-agent was still waiting for NTP sync. |
…#11462) The sled-agent has a mechanism to request the "rude" or "forceful" termination of a VMM process. Forceful termination does not send a request to Propolis to gracefully stop the instance, and instead attempts to immediately destroy the Propolis zone and tear down all sled-agent-internal state related to that instance. Unlike other requests to operate on an instance, forceful termination bypasses the queue of requests to the VMM's `InstanceRunner` task, and if a request to the propolis-server is currently in progress, it will cancel that request immediately. This is intended to ensure that even if the propolis-server process has gotten stuck handling a request for some reason, and therefore, the `InstanceRunner` is in turn stuck waiting for that request to complete, the stuck VMM process can still be killed and its zone cleaned up regardless. See PRs #6915, #7928, and #7548 for additional context around why this mechanism is necessary. Unfortunately, the way this is currently implemented has some...issues, which came up while reviewing PR #11456. The termination request is currently sent using a `tokio::sync::mpsc` channel, which means that the channel can become full, and callers must handle backpressure. This is necessary because callers currently wait for the termination to *complete* by sending a `tokio::sync::oneshot::Sender` over the termination-request channel, which the `InstanceRunner` will send to once the VMM has been terminated. #11456 introduces an infinite retry loop to the termination sequence in order to ensure the zone is destroyed successfully. Because backpressure is exerted on callers who request termination if the termination request channel has filled up, this means that the infinite retry loop there will put callers in a position where they must either load-shed (and therefore be unable to *guarantee* that the termination request has ever made it through), or wait indefinitely for their request to be sent. This was scary to see, so I wanted to see if it could be avoided. This branch changes the implementation of the termination mechanism to remove the use of the `mpsc` channel. This is based on the observation that the goal here is really just to communicate that "you need to shut down", and if multiple callers request that, their requests need not be handled individually: in practice, in the current design, the first such request will actually result in termination, and all the others will sit in the queue until the termination sequence has completed and the `InstanceRunner` drains any other requests. The only reason it works this way today is that a similar `mpsc` request channel with `oneshot` responses is used to place HTTP requests in the queue of the `InstanceManager` for dispatching to the individual `InstanceRunner` tasks, so the same oneshot `tx`en could be sent all the way through to the runner. Since there is no actual need to handle these requests individually, though, we can replace the `mpsc` and `oneshot` with a pair of `tokio::sync::SetOnce` channels: one to signal the termination request, and another to publish that it has completed. This way, the first caller to request termination sets the `signalled` `SetOnce`, and subsequent callers can just see that it has already been signalled without having to wait on a `mpsc` channel. Callers which need to wait for termination to complete and receive the final state (in this case, the `ensure_unregistered` HTTP endpoint) can then wait for the other `SetOnce`. Meanwhile, callers that *don't* actually need to wait for the termination sequence to complete can now choose *not* to wait for that while still knowing that it has been successfully signalled. This means `InstanceManager::use_only_currently_managed_zpools` can no longer block the entire `InstanceManager` from making progress forever, even once #11456 changes the termination process to retry forever when destroying the zone. Other than the change to stop waiting for the termination to complete in `InstanceManager::use_only_currently_managed_zpools`, I've tried to preserve the existing behavior as closely as possible. Just like in the previous code, the first caller to request termination gets to determine the `VmmStateOwner` (i.e. whether or not the final state is published to Nexus). This may deserve to be revisited, and perhaps simplified, later, but this change should leave it the way it was until then. --------- Signed-off-by: Eliza Weisman <[email protected]>
Presently, sled-agent's
InstanceRunnerhas two mechanisms for shutting down a VMM: sending an instance state PUT request to thepropolis-serverprocess for theStoppedstate, or forcibly terminating thepropolis-serverand tearing down the zone. At present, when a request to stop an instance is sent to the sled-agent, it uses the first mechanism, where Propolis is politely asked to stop the instance --- which I'll refer to as "graceful shutdown". The forceful termination path is used when asked to unregister an instance where the VMM has not started up yet, when encountering an unrecoverable VMM error, or when killing an instance that was making use of an expunged disk. Currently, these two paths don't really overlap: when Nexus asks a sled-agent to stop an instance, all it will do is politely ask Propolis to please stop the instance gracefully, and will only fall back to violently shooting the zone in the face if Propolis returns the error that indicates it never knew about that instance in the first place.This means that, should a VMM get stuck while shutting down the instance, stopping it will never complete successfully, and the Propolis zone won't get cleaned up. This can happen due to e.g. a Crucible activation that will never complete. Thus, the sled-agent should attempt to violently terminate a Propolis zone when a graceful shutdown of the VMM fails to complete in a timely manner.
This commit introduces a timeout for the graceful shutdown process. Now, when we send a PUT request to Propolis with the
Stoppedinstance state, the sled-agent will start a 10-minute timer. If no update from Propolis that indicates the instance has transitioned toStoppedis received before the timer completes, the sled-agent will proceed with the forceful termination of the Propolis zone.Fixes #4004.
Closes #6795