Fix race condition when UpdateChannel message is received while fetching participants for previous update

Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
Max Brunsfeld 2023-08-14 17:36:35 -07:00
parent 71454ba27c
commit cbf497bc12
5 changed files with 38 additions and 19 deletions

View file

@ -1156,7 +1156,6 @@ async fn rejoin_room(
channel_members = mem::take(&mut rejoined_room.channel_members);
}
//TODO: move this into the room guard
if let Some(channel_id) = channel_id {
channel_updated(
channel_id,
@ -2453,9 +2452,6 @@ async fn join_channel(
joined_room.clone()
};
// TODO - do this while still holding the room guard,
// currently there's a possible race condition if someone joins the channel
// after we've dropped the lock but before we finish sending these updates
channel_updated(
channel_id,
&joined_room.room,
@ -2748,7 +2744,6 @@ async fn leave_room_for_session(session: &Session) -> Result<()> {
return Ok(());
}
// TODO - do this while holding the room guard.
if let Some(channel_id) = channel_id {
channel_updated(
channel_id,

View file

@ -290,6 +290,7 @@ async fn test_core_channels(
);
}
#[track_caller]
fn assert_participants_eq(participants: &[Arc<User>], expected_partitipants: &[u64]) {
assert_eq!(
participants.iter().map(|p| p.id).collect::<Vec<_>>(),
@ -297,6 +298,7 @@ fn assert_participants_eq(participants: &[Arc<User>], expected_partitipants: &[u
);
}
#[track_caller]
fn assert_members_eq(
members: &[ChannelMembership],
expected_members: &[(u64, bool, proto::channel_member::Kind)],