Skip to content

[sled-agent] remove queueing and backpressure in forceful termination - #11462

Merged
hawkw merged 18 commits into
mainfrom
eliza/ill-be-back-baby
Oct 9, 2026
Merged

hawkw merged 18 commits into
mainfrom
eliza/ill-be-back-baby

Conversation

@hawkw

@hawkw hawkw commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

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 txen 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.

Comment thread sled-agent/src/instance.rs Outdated
) {
self.terminate_tx.send_if_modified(|current| {
if current.is_some() {
return false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could/should this be a SetOnce instead of a watch channel? Assuming "first state_owner to get here wins" is correct, at least - I don't really understand that side of it. It looks like InstanceRunner uses that value to decide whether to publish the state to Nexus - should we allow a state owner of Nexus to overwrite an earlier state owner of Runner? (That seems inherently racy though, which just leaves me with more questions 😬)

@hawkw hawkw Oct 9, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could/should this be a SetOnce instead of a watch channel?

Yes, it should. The only reason it isn't a SetOnce is that I forgot that existed.

Assuming "first state_owner to get here wins" is correct, at least - I don't really understand that side of it. It looks like InstanceRunner uses that value to decide whether to publish the state to Nexus - should we allow a state owner of Nexus to overwrite an earlier state owner of Runner? (That seems inherently racy though, which just leaves me with more questions 😬)

So, this implements the same behavior as the current thing: whichever termination request gets into the channel first decides whether the state gets published to Nexus or not. I've been trying to avoid changing any of the behavior here with this change except for the issue of the backpressure when the old termination channel fills up.

I think the VmmStateOwner stuff may deserve some re-thinking in the future as well, I always found this confusing. I'll have to dig up some of Greg's old commits and try to remember why we even needed to have the "sometimes don't publish state to Nexus" behavior in the first place.

Comment thread sled-agent/src/instance.rs Resolved
Comment thread sled-agent/src/instance.rs Resolved
@hawkw
hawkw force-pushed the eliza/ill-be-back-baby branch from a66832a to 67e4506 Compare October 9, 2026 18:35
hawkw added 14 commits October 9, 2026 11:49
It turns out that the only reason the tests for this module were
`#[cfg(target_os = "illumos")]` was because they used
`VmmReservoir::stub_for_test()`, which was illumos-only...but because
that's a _stub for tests_ which **doesn't** actually manage a real VMM
reservoir, there's really no reason for it to be. All these tests
actually run fine on Linux and macOS (and, presumably, also Windows? I
assume?), so let's let them run on more people's dev machines.

Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
@hawkw
hawkw force-pushed the eliza/ill-be-back-baby branch from ec0df90 to 653409f Compare October 9, 2026 20:18
Signed-off-by: Eliza Weisman <[email protected]>
@hawkw hawkw changed the title sketchy attempt to make InstanceRunner::terminate less deadlockular [sled-agent] remove queueing and backpressure in forceful termination Oct 9, 2026
@hawkw
hawkw marked this pull request as ready for review October 9, 2026 21:07
Comment on lines +518 to +520
/// Released in 1984 and starring Arnold Schwarzenegger and Linda Hamilton, _The
/// Terminator_ is an American science fiction film used to request the forceful
/// termination of a Propolis zone. This is used by the `ensure_unregistered`

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

@bnaecker bnaecker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like some nice cleanup, thanks! Two small suggestions, not blocking.

Comment thread sled-agent/src/instance.rs Resolved
Comment thread sled-agent/src/instance.rs Resolved
let (tx, rx) = oneshot::channel();
// This will fail if the tx has been dropped, which we just...don't do.
let _ = instance.get_filesystem_zpool(tx);
let Ok(Ok(Some(filesystem_pool))) = rx.await else {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this bit from the PR description is quite right:

This means InstanceManager::use_only_currently_managed_zpools can no longer block the entire InstanceManager from making progress forever

because an instance stuck in an infinite retry loop will never respond to this message. Ben's PR already accounted for this by moving this bit off into a new task, and I think this PR's changes means that task can no longer deadlock around termination. But just wanted to note it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, ugh, yeah, that's true. Looking at it, since the RunningZone's root filessytem can't change once it's started, I don't get why this part has to be a whole request-response thing either? It seems like it could also go in a SetOnce that the InstanceRunner publishes once the zone has started, so that callers don't need to wait on that, either.

I'd be happy to put up a change for that too, or we could do it in @bnaecker's branch?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd advocate for a dedicated PR, given that approximately none of the recent PRs have unambiguously fixed subtle locking issues without introducing others :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a change for this almost ready to PR, then!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, actually, after looking closer at it, this part is also a bit sketchy, since if the zone is not yet ensured, we need to wait until a potentially-in-progress propolis ensure finishes. I think we still need to spawn a task as Ben's PR is currently doing, but rather than contending over a single big shared request channel, that task could wait() for the zpool name to be set and then check if the (potentially newly created) zpool is one of the ones that we are getting rid of. I think it actually would make more sense to figure that out in Ben's branch along with the other stuff...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there might still be benefit in doing it that way, because we can avoid the channel filling up, and it's a bit simpler to say instance.filesystem_zpool.wait().await then send requests in a retry loop, but we still have to spawn a task that waits until a potential instance ensure completes regardless.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, in this case, leaving it "actor-y" is probably the best way to ensure that we don't race with creating the zone, but maybe the move here is just to not use try_send in get_filesystem_zpool id the only caller is in a spawned task...

@hawkw
hawkw enabled auto-merge (squash) October 9, 2026 22:52
@hawkw
hawkw merged commit d3dabec into main Oct 9, 2026
19 checks passed
@hawkw
hawkw deleted the eliza/ill-be-back-baby branch October 9, 2026 23:32
jgallagher pushed a commit that referenced this pull request Oct 15, 2026
This change makes it so that sled-agent can ensure that it's using only
currently-managed zpools without using
`use_only_currently_managed_zpools`. :)

At present, the mechanism that sled-agent uses to ensure that any
Propolis zones whose zone-root filesystems are on zpools that no longer
exist is the `InstanceManager::use_only_currently_managed_zpools`
method. This is called in the `InstanceManager` main loop when the set
of currently-managed zpools changes, and works by looping over all
managed instances, asking them which zpool the root filesystem for the
Propolis zone is on, and then telling the `InstanceRunner` to terminate
the Propolis zone if it is on a zpool that is no longer managed. Because
this occurs within the `InstanceManager` main loop, it's important that
nothing that happens here can prevent that loop from making progress
indefinitely, as it would prevent any unrelated instance management
operations from running.

In #11492, I made an attempt to tidy this up a bit by having the
`InstanceRunner` publish its zpool separately from its main request
channel. After thinking it through, though, @smklein, @jgallagher, and I
all came to the conclusion (see [this comment][1]) that there's actually
a much better way of doing this. Rather than having the
`InstanceManager` loop over all *instances* and check if they are using
un-managed zpools, we can just give the `watch` channel of currently
managed zpools to each `InstanceRunner`, and have it wait for changes to
that set and check whether its zpools are still in the currently managed
set.

This avoids a lot of the potential raciness with publishing the zpool
name once the zone is running, since we can just wait to spawn a task to
wait for changes to the set of currently-managed zpools only once a zone
is actually running. After that point, the zpool name will never change,
and we cannot race with creating the zone *or* get stuck if the zone
fails to start. This simplifies a lot of other aspects of the
implementation, too, since it makes one of the two paths to instance
termination completely internal to the `instance.rs` module, and we no
longer have to do any of this work in the `InstanceManager` main loop.
We no longer need the `GetFilesystemZpool` request to the
`InstanceRunner` actor at all, because the task is now spawned with the
zpool name once it's determined. Building on the changes to termination
in #11462, the entire "zpool no longer managed, terminate propolis
forcefully" path is now completely separate from the synchronous (well,
async-but-actor-blocking) request/response channels in both
`InstanceManager` and `InstanceRunner`.

Closes #11492

[1]:
https://github.com/oxidecomputer/omicron/pull/11492/changes/BASE..837f552c06380587eba3526da5236cce68983bea#r4275100226
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants