fix rejoin after quit (#10100)

Release Notes:

- collab: Fixed rejoining channels quickly after a restart
This commit is contained in:
Conrad Irwin 2024-04-02 20:35:14 -06:00 committed by GitHub
parent 8958c9e10f
commit fe7b12c444
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 124 additions and 49 deletions

View file

@ -1203,7 +1203,7 @@ async fn connection_lost(
_ = executor.sleep(RECONNECT_TIMEOUT).fuse() => {
if let Some(session) = session.for_user() {
log::info!("connection lost, removing all resources for user:{}, connection:{:?}", session.user_id(), session.connection_id);
leave_room_for_session(&session).await.trace_err();
leave_room_for_session(&session, session.connection_id).await.trace_err();
leave_channel_buffers_for_session(&session)
.await
.trace_err();
@ -1539,7 +1539,7 @@ async fn leave_room(
response: Response<proto::LeaveRoom>,
session: UserSession,
) -> Result<()> {
leave_room_for_session(&session).await?;
leave_room_for_session(&session, session.connection_id).await?;
response.send(proto::Ack {})?;
Ok(())
}
@ -3023,8 +3023,19 @@ async fn join_channel_internal(
session: UserSession,
) -> Result<()> {
let joined_room = {
leave_room_for_session(&session).await?;
let db = session.db().await;
let mut db = session.db().await;
// If zed quits without leaving the room, and the user re-opens zed before the
// RECONNECT_TIMEOUT, we need to make sure that we kick the user out of the previous
// room they were in.
if let Some(connection) = db.stale_room_connection(session.user_id()).await? {
tracing::info!(
stale_connection_id = %connection,
"cleaning up stale connection",
);
drop(db);
leave_room_for_session(&session, connection).await?;
db = session.db().await;
}
let (joined_room, membership_updated, role) = db
.join_channel(channel_id, session.user_id(), session.connection_id)
@ -4199,7 +4210,7 @@ async fn update_user_contacts(user_id: UserId, session: &Session) -> Result<()>
Ok(())
}
async fn leave_room_for_session(session: &UserSession) -> Result<()> {
async fn leave_room_for_session(session: &UserSession, connection_id: ConnectionId) -> Result<()> {
let mut contacts_to_update = HashSet::default();
let room_id;
@ -4209,7 +4220,7 @@ async fn leave_room_for_session(session: &UserSession) -> Result<()> {
let room;
let channel;
if let Some(mut left_room) = session.db().await.leave_room(session.connection_id).await? {
if let Some(mut left_room) = session.db().await.leave_room(connection_id).await? {
contacts_to_update.insert(session.user_id());
for project in left_room.left_projects.values() {