Clean up guest connection states correctly when a collaborator disconnects

Max Brunsfeld and Nathan Sobo created

This bug was caught by running the executor until parked after tests.

Co-Authored-By: Nathan Sobo <nathan@zed.dev>

Change summary

crates/server/src/rpc/store.rs | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

Detailed changes

crates/server/src/rpc/store.rs 🔗

@@ -296,7 +296,16 @@ impl Store {
                         }
                     }
 
-                    Ok(e.remove())
+                    let project = e.remove();
+                    if let Some(share) = &project.share {
+                        for guest_connection in share.guests.keys() {
+                            if let Some(connection) = self.connections.get_mut(&guest_connection) {
+                                connection.projects.remove(&project_id);
+                            }
+                        }
+                    }
+
+                    Ok(project)
                 } else {
                     Err(anyhow!("no such project"))?
                 }