Commit 0a7cdb16aa
0a7cdb16aab975bd39aba1905bb4eaab88268c58
parent: 6ed8040ddb
Unsigned
Darafei Praliaskouski <me@komzpa.net> · 2026-07-08 13:12 UTC
committer: <strk@kbt.io>
fix: drop connection runtime under entered handle
Layout: unified · split
src/connection.rs
+28 −6
| @@ -100,10 +100,17 @@ pub struct Connection { |
| 100 | 100 | #[allow(dead_code)] |
| 101 | 101 | receiver_task: Rc<Task<()>>, |
| 102 | 102 | client: Option<Client>, |
| 103 | | pub runtime: Rc<Runtime>, |
| 103 | runtime: Option<Rc<Runtime>>, |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | impl Connection { |
| 107 | pub fn runtime(&self) -> Rc<Runtime> { |
| 108 | self.runtime |
| 109 | .as_ref() |
| 110 | .expect("Connection runtime was already dropped") |
| 111 | .clone() |
| 112 | } |
| 113 | |
| 107 | 114 | pub fn client(&self) -> &Client { |
| 108 | 115 | self.client |
| 109 | 116 | .as_ref() |
| @@ -115,7 +122,7 @@ impl Connection { |
| 115 | 122 | F: Future + Send + 'static, |
| 116 | 123 | F::Output: Send + 'static, |
| 117 | 124 | { |
| 118 | | self.runtime |
| 125 | self.runtime() |
| 119 | 126 | .spawn(future) |
| 120 | 127 | .await |
| 121 | 128 | .expect("Tokio error while sending a message") |
| @@ -144,7 +151,7 @@ impl Connection { |
| 144 | 151 | |
| 145 | 152 | Self { |
| 146 | 153 | client: Some(client.clone()), |
| 147 | | runtime: runtime.into(), |
| 154 | runtime: Some(runtime.into()), |
| 148 | 155 | receiver_task: receiver_task.into(), |
| 149 | 156 | } |
| 150 | 157 | } |
| @@ -665,9 +672,24 @@ impl Connection { |
| 665 | 672 | |
| 666 | 673 | impl Drop for Connection { |
| 667 | 674 | fn drop(&mut self) { |
| 668 | | if let Some(client) = self.client.take() { |
| 669 | | let _guard = self.runtime.enter(); |
| 670 | | drop(client); |
| 675 | { |
| 676 | let runtime = self.runtime(); |
| 677 | |
| 678 | if let Some(client) = self.client.take() { |
| 679 | let _guard = runtime.enter(); |
| 680 | drop(client); |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | let Some(runtime) = self.runtime.as_ref() else { |
| 685 | return; |
| 686 | }; |
| 687 | |
| 688 | if Rc::strong_count(runtime) == 1 { |
| 689 | let runtime = self.runtime.take().expect("runtime disappeared"); |
| 690 | let handle = runtime.handle().clone(); |
| 691 | let _guard = handle.enter(); |
| 692 | drop(runtime); |
| 671 | 693 | } |
| 672 | 694 | } |
| 673 | 695 | } |
src/room/mod.rs
+1
| @@ -523,6 +523,7 @@ impl MatrixRoom { |
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | pub fn release_sdk_state(&self) { |
| 526 | self.verification.release_sdk_state(); |
| 526 | 527 | self.room.borrow_mut().take(); |
| 527 | 528 | } |
| 528 | 529 | |
src/room/verification.rs
+4
| @@ -71,6 +71,10 @@ impl Verification { |
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | pub fn release_sdk_state(&self) { |
| 75 | self.inner.borrow_mut().take(); |
| 76 | } |
| 77 | |
| 74 | 78 | pub async fn confirm(&self) { |
| 75 | 79 | let connection = self.connection.borrow().clone(); |
| 76 | 80 | |
src/server.rs
+1 −1
| @@ -1623,7 +1623,7 @@ impl InnerServer { |
| 1623 | 1623 | |
| 1624 | 1624 | pub fn shutdown(&self) { |
| 1625 | 1625 | let connection = self.connection.borrow_mut().take(); |
| 1626 | | let runtime = connection.as_ref().map(|c| c.runtime.clone()); |
| 1626 | let runtime = connection.as_ref().map(|c| c.runtime()); |
| 1627 | 1627 | |
| 1628 | 1628 | if let Some(runtime) = runtime { |
| 1629 | 1629 | let _guard = runtime.enter(); |