Repository navigation
fix(minimald): a listing reads a session's host from a slot the actor publishes #2231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ad0d854
e8a8bc2
ea819ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -189,7 +189,6 @@ enum BoxMessage { | |
| /// The attaching connection's liveness, see [`BoxActor::creator`]. | ||
| Option<std::sync::Weak<()>>, | ||
| ), | ||
| GetHostAttrs(oneshot::Sender<Option<HostAttrs>>), | ||
| /// Hand back this session's host, minting one — with no channel bound to | ||
| /// it — if the session has none running. Used by the exec path, which runs | ||
| /// a command inside the session's sandbox and so needs the sandbox up, but | ||
|
|
@@ -246,6 +245,12 @@ enum BoxMessage { | |
| /// would strand it) or an `Active` with a minted host. A `Draft` that | ||
| /// was merely created isn't busy — nothing is in flight to strand. | ||
| IsBusy(oneshot::Sender<bool>), | ||
| /// Test-only: park the actor for the duration, holding its mailbox the | ||
| /// way a long inline message does. The sender is answered as the park | ||
| /// begins, so a test knows every earlier message, and the publish that | ||
| /// follows it, is done. | ||
| #[cfg(test)] | ||
| Park(std::time::Duration, oneshot::Sender<()>), | ||
| /// Shutdown-stop: kill the host (if any), withdraw the hostname, and stop | ||
| /// the actor — the on-disk record is kept. | ||
| Stop(oneshot::Sender<()>), | ||
|
|
@@ -399,6 +404,8 @@ enum BoxMessage { | |
| #[derive(Debug)] | ||
| pub struct BoxActor { | ||
| receiver: crate::traced::Receiver<BoxMessage>, | ||
| /// The slot this actor's handle reads its host from; see [`HostSlot`]. | ||
| host_slot: HostSlot, | ||
| minimal_state_dir: DaemonAbsPath, | ||
| minimal_cache_dir: DaemonAbsPath, | ||
| daemon_ctx: Arc<mctx::DaemonContext>, | ||
|
|
@@ -633,6 +640,7 @@ impl BoxActor { | |
| workspace_uploads_in_flight: 0, | ||
| creator, | ||
| manager, | ||
| host_slot: Arc::clone(&weak_self.2), | ||
| weak_self, | ||
| destroying, | ||
| // No host yet; the first launch sets this. `Interactive` is the | ||
|
|
@@ -781,7 +789,12 @@ impl BoxActor { | |
| } | ||
| // A weak self-handle so the actor can hand its own mailbox to the | ||
| // runtime objects it spawns without a caller threading it in. | ||
| let weak_self = WeakBoxHandle(sender.downgrade(), destroying.clone()); | ||
| let host_slot = HostSlot::default(); | ||
| let weak_self = WeakBoxHandle( | ||
| sender.downgrade(), | ||
| destroying.clone(), | ||
| Arc::clone(&host_slot), | ||
| ); | ||
| let actor = Self::assemble(conf, receiver, inner, weak_self, destroying.clone()); | ||
|
|
||
| // Register the PTask hostname before the actor goes live, so the | ||
|
|
@@ -808,7 +821,28 @@ impl BoxActor { | |
| session_id = %actor.record.id(), | ||
| ); | ||
| crate::traced::spawn_detached(root, actor.mainloop()); | ||
| Ok(BoxHandle(sender, destroying)) | ||
| Ok(BoxHandle(sender, destroying, host_slot)) | ||
| } | ||
|
|
||
| /// Publishes the host this actor holds to the slot its handle reads | ||
| /// ([`HostSlot`]). Called after every message, so between messages, and | ||
| /// for as long as one parks the actor, the slot holds the host the actor | ||
| /// last had, and a listing's probe never waits on this mailbox. Also | ||
| /// called where a host is installed ([`Self::ensure_host`], | ||
| /// [`Self::mint_session_host`], [`Self::launch_host_for_hooks`]), which | ||
| /// is before the message that launched it replies: a caller that awaits | ||
| /// an attach or `ensure_host` and then reads attrs sees the new host. | ||
| pub(super) fn publish_host(&self) { | ||
| let host = match &self.inner { | ||
| BoxInner::Active { | ||
| host: Some((h, _)), .. | ||
| } => Some(AttrsProbe(h.clone())), | ||
| _ => None, | ||
| }; | ||
| *self | ||
| .host_slot | ||
| .lock() | ||
| .unwrap_or_else(std::sync::PoisonError::into_inner) = host; | ||
| } | ||
|
|
||
| /// Tears the session down for good: its `on_destroy` hooks (failures | ||
|
|
@@ -870,6 +904,8 @@ impl BoxActor { | |
| /// instead of deadlocking against a full manager mailbox. | ||
| async fn mainloop(mut self) { | ||
| let mut teardown = Teardown::ManagerInitiated; | ||
| let _clear_slot = ClearSlotOnExit(Arc::clone(&self.host_slot)); | ||
| self.publish_host(); | ||
| while let Some((msg, caller)) = self.receiver.recv().await { | ||
| // Opened now, a child of the sender's ids (see | ||
| // `traced::Receiver::recv`), so compose, graph resolution and | ||
|
|
@@ -889,6 +925,7 @@ impl BoxActor { | |
| teardown = t; | ||
| break; | ||
| } | ||
| self.publish_host(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two points about when the slot changes. Neither blocks the merge.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both fixed in e36f6cf.
minimal-foundry[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
| if matches!(teardown, Teardown::SelfInitiated) { | ||
| let session_id = *self.record.id(); | ||
|
|
@@ -922,29 +959,6 @@ impl BoxActor { | |
| BoxMessage::EnsureHost(r, session_hnd, conn_username) => { | ||
| let _ = r.send(self.ensure_host(session_hnd, conn_username).await); | ||
| } | ||
| BoxMessage::GetHostAttrs(r) => match &self.inner { | ||
| BoxInner::Active { | ||
| host: Some((h, _)), .. | ||
| } => { | ||
| // Forwarded off-actor for the same reason as | ||
| // `GetWorkspaceDelta`: the host loop can be mid-attach or | ||
| // mid-teardown, and awaiting it from here parks this | ||
| // actor — which the manager awaits in turn, from its own | ||
| // mainloop, where a park costs every session RPC. | ||
| // | ||
| // Bounded *inside* the task: dropping the caller's | ||
| // receiver does not cancel a spawned future, so an | ||
| // unbounded probe would strand one task per poll against | ||
| // a host that never answers. | ||
| let h = h.clone(); | ||
| crate::traced::spawn(async move { | ||
| let _ = r.send(probe_host(h.get_attrs()).await); | ||
| }); | ||
| } | ||
| _ => { | ||
| let _ = r.send(None); | ||
| } | ||
| }, | ||
| BoxMessage::GetWorkspaceDelta(r) => match &self.inner { | ||
| BoxInner::Active { | ||
| host: Some((h, _)), .. | ||
|
|
@@ -966,7 +980,7 @@ impl BoxActor { | |
| host: Some((h, _)), .. | ||
| } => { | ||
| // Off-actor and bounded for the same reasons as | ||
| // `GetHostAttrs`. | ||
| // `GetWorkspaceDelta`. | ||
| let h = h.clone(); | ||
| crate::traced::spawn(async move { | ||
| let _ = r.send(probe_host(h.get_screen()).await); | ||
|
|
@@ -1027,6 +1041,15 @@ impl BoxActor { | |
| BoxMessage::Rename(new_name, r) => { | ||
| let _ = r.send(self.rename(new_name).await); | ||
| } | ||
| #[cfg(test)] | ||
| BoxMessage::Park(d, entered) => { | ||
| #[expect( | ||
| clippy::let_underscore_must_use, | ||
| reason = "the parker may already be gone; the park still runs" | ||
| )] | ||
| let _ = entered.send(()); | ||
| tokio::time::sleep(d).await; | ||
| } | ||
| BoxMessage::IsBusy(r) => { | ||
| let _ = r.send(match &self.inner { | ||
| // Awaiting a verdict: a client is mid create flow. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.