[pdm-devel] [PATCH datacenter-manager 5/6] ui: node status: handle the request via an AsyncAbortGuard

Shannon Sterz s.sterz at proxmox.com
Thu Nov 27 16:36:08 CET 2025


this makes it possible to abort a request when another one is
triggered here. in theory this could also trigger a race condition
with a potential login. however, as a user would need to trigger it
manually, this is rather unlikely to happen in practice.

Signed-off-by: Shannon Sterz <s.sterz at proxmox.com>
---
 ui/src/administration/node_status.rs | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/ui/src/administration/node_status.rs b/ui/src/administration/node_status.rs
index cce3426..a3338bb 100644
--- a/ui/src/administration/node_status.rs
+++ b/ui/src/administration/node_status.rs
@@ -7,6 +7,7 @@ use proxmox_node_status::NodePowerCommand;
 use proxmox_yew_comp::{http_post, ConfirmButton, NodeStatusPanel};
 use pwt::prelude::*;
 use pwt::widget::{Column, Container, Row};
+use pwt::AsyncAbortGuard;
 
 #[derive(Properties, Clone, PartialEq)]
 pub(crate) struct NodeStatus {}
@@ -31,18 +32,22 @@ enum Msg {
 
 struct PdmNodeStatus {
     error: Option<Error>,
+    abort_guard: Option<AsyncAbortGuard>,
 }
 
 impl PdmNodeStatus {
-    fn change_power_state(&self, ctx: &yew::Context<Self>, command: NodePowerCommand) {
-        ctx.link().send_future(async move {
+    fn change_power_state(&mut self, ctx: &yew::Context<Self>, command: NodePowerCommand) {
+        let link = ctx.link().clone();
+        self.abort_guard.replace(AsyncAbortGuard::spawn(async move {
             let data = Some(serde_json::json!({"command": command}));
 
-            match http_post("/nodes/localhost/status", data).await {
+            let res = match http_post("/nodes/localhost/status", data).await {
                 Ok(()) => Msg::Reload,
                 Err(e) => Msg::Error(e),
-            }
-        });
+            };
+
+            link.send_message(res);
+        }));
     }
 }
 
@@ -51,7 +56,10 @@ impl Component for PdmNodeStatus {
     type Properties = NodeStatus;
 
     fn create(_ctx: &yew::Context<Self>) -> Self {
-        Self { error: None }
+        Self {
+            error: None,
+            abort_guard: None,
+        }
     }
 
     fn update(&mut self, ctx: &yew::Context<Self>, msg: Self::Message) -> bool {
-- 
2.47.3





More information about the pdm-devel mailing list