Fix terminating the ongoing process in securejoin

When securejoin allocated an ongoing process it was never freed
again.  This fixes this and also adds test coverage for the right
ongoing behaviour.
This commit is contained in:
Floris Bruynooghe
2021-02-17 20:53:34 +01:00
parent e1fec6a460
commit 24cb6aa9a4
2 changed files with 10 additions and 2 deletions

View File

@@ -119,7 +119,9 @@ impl<'a> BobStateHandle<'a> {
/// Note that the state is only cleared on Drop since otherwise the invariant that the
/// state is always consistent is violated. However the "ongoing" prococess is released
/// here a little bit earlier as this requires access to the Context, which we do not
/// have on Drop (Drop can not run asynchronous code).
/// have on Drop (Drop can not run asynchronous code). Stopping the "ongoing" process
/// will release [`securejoin`](super::securejoin) which in turn will finally free the
/// ongoing process using [`Context::free_ongoing`].
///
/// [`InnerContext::bob`]: crate::context::InnerContext::bob
/// [`Bob`]: super::Bob

View File

@@ -102,7 +102,7 @@ impl Bob {
}
Err(err) => {
if did_alloc_ongoing {
context.stop_ongoing().await;
context.free_ongoing().await;
}
Err(err)
}
@@ -291,6 +291,7 @@ async fn securejoin(context: &Context, qr: &str) -> Result<ChatId, JoinError> {
Ok((chatid, _is_protected, _blocked)) => break chatid,
Err(err) => {
if start.elapsed() > Duration::from_secs(7) {
context.free_ongoing().await;
return Err(JoinError::MissingChat(err));
}
}
@@ -298,6 +299,7 @@ async fn securejoin(context: &Context, qr: &str) -> Result<ChatId, JoinError> {
}
async_std::task::sleep(Duration::from_millis(50)).await;
};
context.free_ongoing().await;
Ok(chatid)
}
}
@@ -940,6 +942,7 @@ mod tests {
dc_join_securejoin(&bob.ctx, &qr).await.unwrap();
let sent = bob.pop_sent_msg().await;
assert!(!bob.ctx.has_ongoing().await);
assert_eq!(sent.recipient(), "alice@example.com".parse().unwrap());
let msg = alice.parse_msg(&sent).await;
assert!(!msg.was_encrypted());
@@ -1170,6 +1173,7 @@ mod tests {
_ => panic!("Wrong event type"),
}
}
assert!(!bob.ctx.has_ongoing().await);
// Check Bob sent the right handshake message.
let sent = bob.pop_sent_msg().await;
@@ -1285,6 +1289,7 @@ mod tests {
};
let sent = bob.pop_sent_msg().await;
assert!(bob.ctx.has_ongoing().await);
assert_eq!(sent.recipient(), "alice@example.com".parse().unwrap());
let msg = alice.parse_msg(&sent).await;
assert!(!msg.was_encrypted());
@@ -1403,5 +1408,6 @@ mod tests {
let bob_chatid = joiner.await;
let bob_chat = Chat::load_from_db(&bob.ctx, bob_chatid).await.unwrap();
assert!(bob_chat.is_protected());
assert!(!bob.ctx.has_ongoing().await)
}
}