From 7644ceea8a0fd936f6a2830390300bcfb75934a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Fri, 9 Jul 2021 14:31:54 +0200 Subject: [PATCH] crypto: Make sure we don't deadlock when we cancel the verification request --- .../src/verification/requests.rs | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/matrix_sdk_crypto/src/verification/requests.rs b/matrix_sdk_crypto/src/verification/requests.rs index 435e7e03..7e4fa6df 100644 --- a/matrix_sdk_crypto/src/verification/requests.rs +++ b/matrix_sdk_crypto/src/verification/requests.rs @@ -385,15 +385,6 @@ impl VerificationRequest { /// Cancel the verification request pub fn cancel(&self) -> Option { - if let Some(verification) = - self.verification_cache.get(self.other_user(), self.flow_id().as_str()) - { - match verification { - crate::Verification::SasV1(s) => s.cancel(), - crate::Verification::QrV1(q) => q.cancel(), - }; - } - let mut inner = self.inner.lock().unwrap(); inner.cancel(true, &CancelCode::User); @@ -403,14 +394,27 @@ impl VerificationRequest { None }; - content.map(|c| match c { + let request = content.map(|c| match c { OutgoingContent::ToDevice(content) => { ToDeviceRequest::new(&self.other_user(), inner.other_device_id(), content).into() } OutgoingContent::Room(room_id, content) => { RoomMessageRequest { room_id, txn_id: Uuid::new_v4(), content }.into() } - }) + }); + + drop(inner); + + if let Some(verification) = + self.verification_cache.get(self.other_user(), self.flow_id().as_str()) + { + match verification { + crate::Verification::SasV1(s) => s.cancel(), + crate::Verification::QrV1(q) => q.cancel(), + }; + } + + request } pub(crate) fn receive_ready(&self, sender: &UserId, content: &ReadyContent) {