From 34efb23bf61fd9281645b8b321e44fe724ba85be Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Mon, 22 Jan 2024 21:59:48 -0700 Subject: [PATCH] Fix a circular reference between Client and UserStore Before this change once the UserStore had been created, the Client would never be dropped. --- crates/client/src/user.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/client/src/user.rs b/crates/client/src/user.rs index dcab0e53942032045d5dcdc117e1c0e3adbe7c9e..122046827ac60273e689528b659c482ba74d04ef 100644 --- a/crates/client/src/user.rs +++ b/crates/client/src/user.rs @@ -146,7 +146,13 @@ impl UserStore { }), _maintain_current_user: cx.spawn(|this, mut cx| async move { let mut status = client.status(); + let weak = Arc::downgrade(&client); + drop(client); while let Some(status) = status.next().await { + // if the client is dropped, the app is shutting down. + let Some(client) = weak.upgrade() else { + return Ok(()); + }; match status { Status::Connected { .. } => { if let Some(user_id) = client.user_id() {