mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
Hack to fix group chat creation race condition
In the current design the dc_receive_imf() pipeline calls handle_securejoin_handshake() before it creates the group. However handle_securejoin_handshake() already signals to securejoin() that the chat exists, which is not true. The proper fix would be to re-desing how group-creation works, potentially allowinng handle_securejoin_handshake() to already create the group and no longer require any further processing by dc_receive_imf().
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
//! Verified contact protocol implementation as [specified by countermitm project](https://countermitm.readthedocs.io/en/stable/new.html#setup-contact-protocol)
|
//! Verified contact protocol implementation as [specified by countermitm project](https://countermitm.readthedocs.io/en/stable/new.html#setup-contact-protocol)
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use percent_encoding::{utf8_percent_encode, AsciiSet, NON_ALPHANUMERIC};
|
use percent_encoding::{utf8_percent_encode, AsciiSet, NON_ALPHANUMERIC};
|
||||||
|
|
||||||
@@ -351,6 +351,27 @@ async fn securejoin(context: &Context, qr: &str) -> ChatId {
|
|||||||
while !context.shall_stop_ongoing().await {
|
while !context.shall_stop_ongoing().await {
|
||||||
async_std::task::sleep(Duration::from_millis(50)).await;
|
async_std::task::sleep(Duration::from_millis(50)).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle_securejoin_handshake() calls Context::stop_ongoing before the group chat
|
||||||
|
// is created (it is created after handle_securejoin_handshake() returns by
|
||||||
|
// dc_receive_imf()). As a hack we just wait a bit for it to appear.
|
||||||
|
let start = Instant::now();
|
||||||
|
while start.elapsed() < Duration::from_secs(7) {
|
||||||
|
{
|
||||||
|
let bob = context.bob.read().await;
|
||||||
|
if chat::get_chat_id_by_grpid(
|
||||||
|
context,
|
||||||
|
bob.qr_scan.as_ref().unwrap().text2.as_ref().unwrap(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.is_ok()
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async_std::task::sleep(Duration::from_millis(50)).await
|
||||||
|
}
|
||||||
|
|
||||||
cleanup(&context, contact_chat_id, true, join_vg).await
|
cleanup(&context, contact_chat_id, true, join_vg).await
|
||||||
} else {
|
} else {
|
||||||
// for a one-to-one-chat, the chat is already known, return the chat-id,
|
// for a one-to-one-chat, the chat is already known, return the chat-id,
|
||||||
|
|||||||
Reference in New Issue
Block a user