fix: if I have one more deadlock I'm going to lose my mind

This commit is contained in:
2025-12-07 01:16:30 -05:00
Unverified
parent f7305e4b43
commit f1cfe7e344

View File

@@ -259,6 +259,12 @@ async fn handle_connection(
// Terminate games if a player makes an invalid move // Terminate games if a player makes an invalid move
if invalid { if invalid {
let current_match_id = current_match.id; let current_match_id = current_match.id;
let viewers = current_match.viewers.clone();
drop(current_match);
drop(matches_guard);
drop(client);
drop(clients_guard);
if sd.demo_mode { if sd.demo_mode {
terminate_match(current_match_id, &sd.matches, &sd.clients, &sd.observers, sd.demo_mode).await; terminate_match(current_match_id, &sd.matches, &sd.clients, &sd.observers, sd.demo_mode).await;
@@ -266,11 +272,7 @@ async fn handle_connection(
} else { } else {
let _ = send(&tx, "GAME:LOSS"); let _ = send(&tx, "GAME:LOSS");
let _ = send(&opponent_connection, "GAME:WINS"); let _ = send(&opponent_connection, "GAME:WINS");
broadcast_message(&current_match.viewers, &sd.observers, &format!("GAME:WIN:{}", opponent_username)).await; broadcast_message(&viewers, &sd.observers, &format!("GAME:WIN:{}", opponent_username)).await;
drop(client);
drop(current_match);
drop(clients_guard);
let mut clients_guard = sd.clients.write().await; let mut clients_guard = sd.clients.write().await;
let mut client = clients_guard.get_mut(&addr).unwrap().write().await; let mut client = clients_guard.get_mut(&addr).unwrap().write().await;
@@ -284,7 +286,7 @@ async fn handle_connection(
opponent.score += 1; opponent.score += 1;
drop(opponent); drop(opponent);
matches_guard.remove(&current_match_id).unwrap(); sd.matches.write().await.remove(&current_match_id).unwrap();
} }
continue; continue;
} else { } else {