From 74aeec360d03d23a3ec878fb517336495a99ea88 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 26 Jan 2023 16:44:55 +0100 Subject: [PATCH 1/3] Cancel pending call when participant leaves room after a reconnection Previously, if a user temporarily disconnected while there was a pending call, we would fail to cancel such pending call when the caller left the room. This was due to the caller reconnecting and having a different connection id than the one originally used to initiate the call. --- crates/collab/src/db.rs | 8 ++------ .../collab/src/tests/randomized_integration_tests.rs | 10 ++++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/crates/collab/src/db.rs b/crates/collab/src/db.rs index 63ea7fdd9e..3358652feb 100644 --- a/crates/collab/src/db.rs +++ b/crates/collab/src/db.rs @@ -1586,12 +1586,8 @@ impl Database { .filter( Condition::all() .add( - room_participant::Column::CallingConnectionId - .eq(connection.id as i32), - ) - .add( - room_participant::Column::CallingConnectionServerId - .eq(connection.owner_id as i32), + room_participant::Column::CallingUserId + .eq(leaving_participant.user_id), ) .add(room_participant::Column::AnsweringConnectionId.is_null()), ) diff --git a/crates/collab/src/tests/randomized_integration_tests.rs b/crates/collab/src/tests/randomized_integration_tests.rs index e0170f6648..4783957dbb 100644 --- a/crates/collab/src/tests/randomized_integration_tests.rs +++ b/crates/collab/src/tests/randomized_integration_tests.rs @@ -166,12 +166,10 @@ async fn test_random_collaboration( let contacts = server.app_state.db.get_contacts(*user_id).await.unwrap(); let pool = server.connection_pool.lock(); for contact in contacts { - if let db::Contact::Accepted { user_id, .. } = contact { - if pool.is_user_online(user_id) { - assert_ne!( - user_id, removed_user_id, - "removed client is still a contact of another peer" - ); + if let db::Contact::Accepted { user_id, busy, .. } = contact { + if user_id == removed_user_id { + assert!(!pool.is_user_online(user_id)); + assert!(!busy); } } } From eca6115e4badec7be52695172b07ee9f495ec235 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 26 Jan 2023 17:22:45 +0100 Subject: [PATCH 2/3] Ensure `proto::UpdateWorktree::removed_entries` doesn't exceed chunk size This was causing the database to panic because we were trying to remove too many entries at once. --- crates/rpc/src/proto.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/crates/rpc/src/proto.rs b/crates/rpc/src/proto.rs index 6b09f07db4..1a56abc783 100644 --- a/crates/rpc/src/proto.rs +++ b/crates/rpc/src/proto.rs @@ -9,7 +9,7 @@ use std::fmt; use std::{ cmp, fmt::Debug, - io, iter, mem, + io, iter, time::{Duration, SystemTime, UNIX_EPOCH}, }; @@ -489,16 +489,26 @@ pub fn split_worktree_update( return None; } - let chunk_size = cmp::min(message.updated_entries.len(), max_chunk_size); - let updated_entries = message.updated_entries.drain(..chunk_size).collect(); - done = message.updated_entries.is_empty(); + let updated_entries_chunk_size = cmp::min(message.updated_entries.len(), max_chunk_size); + let updated_entries = message + .updated_entries + .drain(..updated_entries_chunk_size) + .collect(); + + let removed_entries_chunk_size = cmp::min(message.removed_entries.len(), max_chunk_size); + let removed_entries = message + .removed_entries + .drain(..removed_entries_chunk_size) + .collect(); + + done = message.updated_entries.is_empty() && message.removed_entries.is_empty(); Some(UpdateWorktree { project_id: message.project_id, worktree_id: message.worktree_id, root_name: message.root_name.clone(), abs_path: message.abs_path.clone(), updated_entries, - removed_entries: mem::take(&mut message.removed_entries), + removed_entries, scan_id: message.scan_id, is_last_update: done && message.is_last_update, }) From 647d9861b1e077602921ce8338153fcd5a84e080 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 27 Jan 2023 09:50:59 +0100 Subject: [PATCH 3/3] Abort collaboration process if any thread panics --- Cargo.toml | 2 -- Dockerfile | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 77469c0623..39e4cd6367 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -84,5 +84,3 @@ split-debuginfo = "unpacked" [profile.release] debug = true - - diff --git a/Dockerfile b/Dockerfile index 5a6279a95e..d3170696c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,7 @@ WORKDIR app COPY . . # Compile collab server +ARG CARGO_PROFILE_RELEASE_PANIC=abort RUN --mount=type=cache,target=./script/node_modules \ --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=./target \