From 0491747eed76bb582f34e443787ad008501341b5 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 18 Oct 2022 17:42:10 +0200 Subject: [PATCH] Only leave room on connections that are associated with the active call Co-Authored-By: Nathan Sobo --- crates/collab/src/integration_tests.rs | 12 ++++++++++-- crates/collab/src/rpc.rs | 4 ++++ crates/collab/src/rpc/store.rs | 12 +++++++----- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/crates/collab/src/integration_tests.rs b/crates/collab/src/integration_tests.rs index e715a995a7c9ce4d331eb4bc9a1e237eead0fa56..294ebd75f278f9a11fdf015c86f868bd1e9709d1 100644 --- a/crates/collab/src/integration_tests.rs +++ b/crates/collab/src/integration_tests.rs @@ -468,6 +468,14 @@ async fn test_calls_on_multiple_connections( assert!(incoming_call_b1.next().await.unwrap().is_none()); assert!(incoming_call_b2.next().await.unwrap().is_none()); + // User B disconnects the client that is not on the call. Everything should be fine. + client_b1.disconnect(&cx_b1.to_async()).unwrap(); + deterministic.advance_clock(rpc::RECEIVE_TIMEOUT); + client_b1 + .authenticate_and_connect(false, &cx_b1.to_async()) + .await + .unwrap(); + // User B hangs up, and user A calls them again. active_call_b2.update(cx_b2, |call, cx| call.hang_up(cx).unwrap()); deterministic.run_until_parked(); @@ -520,9 +528,9 @@ async fn test_calls_on_multiple_connections( assert!(incoming_call_b1.next().await.unwrap().is_some()); assert!(incoming_call_b2.next().await.unwrap().is_some()); - // User A disconnects up, causing both connections to stop ringing. + // User A disconnects, causing both connections to stop ringing. server.disconnect_client(client_a.current_user_id(cx_a)); - cx_a.foreground().advance_clock(rpc::RECEIVE_TIMEOUT); + deterministic.advance_clock(rpc::RECEIVE_TIMEOUT); assert!(incoming_call_b1.next().await.unwrap().is_none()); assert!(incoming_call_b2.next().await.unwrap().is_none()); } diff --git a/crates/collab/src/rpc.rs b/crates/collab/src/rpc.rs index bb8d7c2325680682eed81b2b119f76c5ba2d4119..fc8a23f6691d34302549892564dd105c8de6fbb2 100644 --- a/crates/collab/src/rpc.rs +++ b/crates/collab/src/rpc.rs @@ -477,6 +477,10 @@ impl Server { let mut contacts_to_update = HashSet::default(); { let mut store = self.store().await; + + #[cfg(test)] + let removed_connection = store.remove_connection(connection_id).unwrap(); + #[cfg(not(test))] let removed_connection = store.remove_connection(connection_id)?; for project in removed_connection.hosted_projects { diff --git a/crates/collab/src/rpc/store.rs b/crates/collab/src/rpc/store.rs index fb21538d60b8f1c45ebfb3cdc4ca206c1b715f47..ee7d3e258704d5ff48d916368e8cb638a60cc329 100644 --- a/crates/collab/src/rpc/store.rs +++ b/crates/collab/src/rpc/store.rs @@ -215,11 +215,13 @@ impl Store { let connected_user = self.connected_users.get(&user_id).unwrap(); if let Some(active_call) = connected_user.active_call.as_ref() { let room_id = active_call.room_id; - let left_room = self.leave_room(room_id, connection_id)?; - result.hosted_projects = left_room.unshared_projects; - result.guest_projects = left_room.left_projects; - result.room_id = Some(room_id); - result.canceled_call_connection_ids = left_room.canceled_call_connection_ids; + if active_call.connection_id == Some(connection_id) { + let left_room = self.leave_room(room_id, connection_id)?; + result.hosted_projects = left_room.unshared_projects; + result.guest_projects = left_room.left_projects; + result.room_id = Some(room_id); + result.canceled_call_connection_ids = left_room.canceled_call_connection_ids; + } } let connected_user = self.connected_users.get_mut(&user_id).unwrap();