Commit 04e248d064

04e248d0641fc4f999d3257a67fbc0ce1bc01ade

parent: ae6b160e6b

Unsigned

Darafei Praliaskouski <me@komzpa.net> · 2026-07-06 06:38 UTC
committer: <strk@kbt.io>

fix: drop Matrix client inside runtime

Layout: unified · split

src/connection.rs +16 −5
@@ -99,13 +99,15 @@ pub enum ClientMessage {
9999pub struct Connection {
100100 #[allow(dead_code)]
101101 receiver_task: Rc<Task<()>>,
102 client: Client,
102 client: Option<Client>,
103103 pub runtime: Rc<Runtime>,
104104}
105105
106106impl Connection {
107107 pub fn client(&self) -> &Client {
108 &self.client
108 self.client
109 .as_ref()
110 .expect("Connection client was already dropped")
109111 }
110112
111113 pub async fn spawn<F>(&self, future: F) -> F::Output
@@ -141,7 +143,7 @@ impl Connection {
141143 ));
142144
143145 Self {
144 client: client.clone(),
146 client: Some(client.clone()),
145147 runtime: runtime.into(),
146148 receiver_task: receiver_task.into(),
147149 }
@@ -180,7 +182,7 @@ impl Connection {
180182 devices: Vec<OwnedDeviceId>,
181183 auth_info: Option<InteractiveAuthInfo>,
182184 ) -> MatrixResult<DeleteDevicesResponse> {
183 let client = self.client.clone();
185 let client = self.client().clone();
184186 Ok(self
185187 .spawn(async move {
186188 if let Some(info) = auth_info {
@@ -216,7 +218,7 @@ impl Connection {
216218
217219 /// Get the list of our own devices.
218220 pub async fn devices(&self) -> MatrixResult<DevicesResponse> {
219 let client = self.client.clone();
221 let client = self.client().clone();
220222 Ok(self.spawn(async move { client.devices().await }).await?)
221223 }
222224
@@ -660,3 +662,12 @@ impl Connection {
660662 }
661663 }
662664}
665
666impl Drop for Connection {
667 fn drop(&mut self) {
668 if let Some(client) = self.client.take() {
669 let _guard = self.runtime.enter();
670 drop(client);
671 }
672 }
673}