Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion crates/phase-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ async fn main() {
}
}
// Notify connected players and clean up persistence
let conns = bg_connections.lock().await;
let mut conns = bg_connections.lock().await;
for game_code in &expired {
info!(game = %game_code, reason = "disconnect_expired", "game over");
if let Some(players) = conns.get(game_code) {
Expand All @@ -1100,6 +1100,10 @@ async fn main() {
if let Err(e) = bg_game_db.delete_session(game_code) {
error!(game = %game_code, error = %e, "failed to delete persisted session");
}
// Prune the connections entry for the finished game so the map
// does not grow unbounded (mirrors the game_spectators cleanup
// below). The immutable `conns.get` borrow above has ended.
conns.remove(game_code);
}
let mut specs = bg_game_spectators.lock().await;
for game_code in &expired {
Expand Down Expand Up @@ -1135,6 +1139,15 @@ async fn main() {
}
}
drop(mgr);
// Prune the connections entries for the expired lobby games so the
// map does not grow unbounded (mirrors the game_spectators cleanup
// below). Lock order: state (dropped) -> connections -> spectators.
{
let mut conns = bg_connections.lock().await;
for game_code in &expired_lobby {
conns.remove(game_code);
}
}
let mut specs = bg_game_spectators.lock().await;
for game_code in &expired_lobby {
specs.remove(game_code);
Expand Down
Loading