Skip to content

Commit

Permalink
Fix deadlock preventing connections from being dropped
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Jan 15, 2025
1 parent f4a79f5 commit ed666a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
20 changes: 10 additions & 10 deletions src/modules/main_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,17 @@ pub async fn run_main_server(server: Arc<ServerState>) {
if let Some(connection) = connection {
info!("Connection {} from {} closed", connection.id, addr);
state.server.connections.lock().await.remove(&connection);
// Inlining this variable will cause the lock to not be dropped, causing a deadlock in handle_message
let friends: Vec<Uuid> = connection
.state
.lock()
.await
.open_to_friends
.iter()
.copied()
.collect();
message_handler::handle_message(
WorldHostC2SMessage::ClosedWorld {
friends: connection
.state
.lock()
.await
.open_to_friends
.iter()
.copied()
.collect(),
},
WorldHostC2SMessage::ClosedWorld { friends },
&connection,
&state.server,
)
Expand Down
5 changes: 2 additions & 3 deletions src/protocol/join_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ impl JoinType {
}),
JoinType::Proxy => {
let external_proxy = if connection.protocol_version >= 3 {
&connection.state.lock().await.external_proxy
connection.state.lock().await.external_proxy.clone()
} else {
&None
None
};

let base_addr = external_proxy
Expand All @@ -51,7 +51,6 @@ impl JoinType {
.or_else(|| config.base_addr.clone())?;

let port = external_proxy
.clone()
.map(|p| p.mc_port)
.unwrap_or_else(|| config.ex_java_port);

Expand Down

0 comments on commit ed666a3

Please sign in to comment.