public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Shannon Sterz <s.sterz@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH datacenter-manager 2/6] ui: main: move requests into an async pool and drop it on logout
Date: Thu, 27 Nov 2025 16:36:05 +0100	[thread overview]
Message-ID: <20251127153609.440415-4-s.sterz@proxmox.com> (raw)
In-Reply-To: <20251127153609.440415-1-s.sterz@proxmox.com>

this will abort requests that are still in flight during a log out.
such requests can then end up in a race condition with the next login.
if the login goes through before these requests return, a user will be
logged out right after logging in again.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
---
 ui/src/main.rs | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/ui/src/main.rs b/ui/src/main.rs
index 026b7ab..985220c 100644
--- a/ui/src/main.rs
+++ b/ui/src/main.rs
@@ -12,6 +12,7 @@ use pwt::prelude::*;
 use pwt::props::TextRenderFn;
 use pwt::state::{Loader, PersistentState, SharedStateObserver};
 use pwt::widget::{Column, DesktopApp, Dialog, Mask};
+use pwt::AsyncPool;
 
 use pbs_api_types::TaskListItem;
 use proxmox_login::Authentication;
@@ -60,6 +61,8 @@ struct DatacenterManagerApp {
     view_list: Vec<String>,
     view_list_context: ViewListContext,
     _view_list_observer: SharedStateObserver<usize>,
+
+    async_pool: AsyncPool,
 }
 
 async fn check_subscription() -> Msg {
@@ -95,7 +98,8 @@ impl DatacenterManagerApp {
                 if self.subscription_confirmed {
                     ctx.link().send_message(Msg::ConfirmSubscription);
                 } else {
-                    ctx.link().send_future(check_subscription());
+                    self.async_pool
+                        .send_future(ctx.link().clone(), check_subscription());
                 }
             } else {
                 ctx.link().send_message(Msg::ConfirmSubscription);
@@ -103,13 +107,13 @@ impl DatacenterManagerApp {
             }
             //ctx.link().send_future_batch(get_fingerprint());
             //
-            self.remote_list_timeout = Self::poll_remote_list(ctx, true);
+            self.remote_list_timeout = self.poll_remote_list(ctx, true);
             self.update_views(ctx);
         }
     }
 
     fn update_views(&mut self, ctx: &Context<Self>) {
-        ctx.link().send_future(async move {
+        self.async_pool.send_future(ctx.link().clone(), async move {
             let res = http_get("/config/views", None)
                 .await
                 .map(|list: Vec<ViewConfig>| {
@@ -123,7 +127,7 @@ impl DatacenterManagerApp {
     }
 
     fn update_remotes(&mut self, ctx: &Context<Self>, result: MsgRemoteList) -> bool {
-        self.remote_list_timeout = Self::poll_remote_list(ctx, false);
+        self.remote_list_timeout = self.poll_remote_list(ctx, false);
         let mut changed = false;
         match result {
             Err(err) => {
@@ -160,10 +164,13 @@ impl DatacenterManagerApp {
         changed
     }
 
-    fn poll_remote_list(ctx: &Context<Self>, first: bool) -> Option<Timeout> {
+    fn poll_remote_list(&self, ctx: &Context<Self>, first: bool) -> Option<Timeout> {
         let link = ctx.link().clone();
+        let async_pool = self.async_pool.clone();
         let timeout = Timeout::new(if first { 0 } else { 5_000 }, move || {
-            link.send_future(async move { Msg::RemoteList(Self::get_remote_list().await) })
+            async_pool.send_future(link, async move {
+                Msg::RemoteList(Self::get_remote_list().await)
+            })
         });
         Some(timeout)
     }
@@ -226,6 +233,7 @@ impl Component for DatacenterManagerApp {
             view_list: Vec::new(),
             view_list_context,
             _view_list_observer,
+            async_pool: AsyncPool::new(),
         };
 
         this.on_login(ctx, false);
@@ -249,6 +257,8 @@ impl Component for DatacenterManagerApp {
             }
             Msg::Logout => {
                 //log::info!("CLEAR COOKIE");
+                // this will drop the pool and abort all current requests
+                self.async_pool = AsyncPool::new();
                 self.running_tasks.abort();
                 self.remote_list_timeout = None;
                 proxmox_yew_comp::http_clear_auth();
-- 
2.47.3



_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel


  parent reply	other threads:[~2025-11-27 15:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-27 15:36 [pdm-devel] [PATCH datacenter-manager/yew-widget-toolkit 0/7] avoid more race conditions on log in Shannon Sterz
2025-11-27 15:36 ` [pdm-devel] [PATCH yew-widget-toolkit 1/1] loader: add helper to allow aborting a load Shannon Sterz
2025-11-27 18:22   ` [pdm-devel] applied: " Thomas Lamprecht
2025-11-27 15:36 ` [pdm-devel] [PATCH datacenter-manager 1/6] ui: main: abort running task load on log out Shannon Sterz
2025-11-27 15:36 ` Shannon Sterz [this message]
2025-11-27 15:36 ` [pdm-devel] [PATCH datacenter-manager 3/6] ui: main: only render acl context when we are logged in Shannon Sterz
2025-11-27 15:36 ` [pdm-devel] [PATCH datacenter-manager 4/6] ui: resource tree: use an async pool for requests Shannon Sterz
2025-11-27 15:36 ` [pdm-devel] [PATCH datacenter-manager 5/6] ui: node status: handle the request via an AsyncAbortGuard Shannon Sterz
2025-11-27 15:36 ` [pdm-devel] [PATCH datacenter-manager 6/6] ui: top nav bar: use an abort guard for loading the version Shannon Sterz
2025-11-27 20:54 ` [pdm-devel] applied: [PATCH datacenter-manager/yew-widget-toolkit 0/7] avoid more race conditions on log in Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251127153609.440415-4-s.sterz@proxmox.com \
    --to=s.sterz@proxmox.com \
    --cc=pdm-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal