Skip to content

Commit

Permalink
fix(api-status): auto-delete lobby after testing connection (#770)
Browse files Browse the repository at this point in the history
<!-- Please make sure there is an issue that this PR is correlated to. -->

## Changes

<!-- If there are frontend changes, please include screenshots. -->
  • Loading branch information
NathanFlurry committed May 15, 2024
1 parent 12bf1d4 commit 9803f39
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions svc/api/status/src/route/matchmaker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,51 @@ pub async fn status(
}
};

let port_default = unwrap!(res.lobby.ports.get("default"));
// Test connection, defer error
let lobby_id = res.lobby.lobby_id.clone();
let test_res = tokio::time::timeout(
Duration::from_secs(15),
test_lobby_connection(res.lobby, res.player),
)
.await;

// Shut down lobby regardless of connection status
//
// This way if the connection fails to connect, we still clean up the lobby instead of spamming
// lobbies with unconnected players
msg!([ctx] mm::msg::lobby_stop(lobby_id) {
lobby_id: Some(lobby_id.into()),
})
.await?;

// Unwrap res
match test_res {
Ok(Ok(())) => {}
Ok(Err(err)) => {
return Err(err);
}
Err(_) => {
bail_with!(
INTERNAL_STATUS_CHECK_FAILED,
error = "test lobby connection timed out"
)
}
}
// if let Err(err) = test_res {
// return Err(err);
// }

Ok(serde_json::json!({}))
}

async fn test_lobby_connection(
lobby: Box<models::MatchmakerJoinLobby>,
player: Box<models::MatchmakerJoinPlayer>,
) -> GlobalResult<()> {
let port_default = unwrap!(lobby.ports.get("default"));
let host = unwrap_ref!(port_default.host);
let hostname = &port_default.hostname;
let token = &res.player.token;
let token = &player.token;

// Look up IP for GG nodes
let gg_ips = lookup_dns(hostname).await?;
Expand Down Expand Up @@ -200,7 +241,7 @@ pub async fn status(
)
})?;

Ok(serde_json::json!({}))
Ok(())
}

/// Returns the IP addresses for a given hostname.
Expand Down

0 comments on commit 9803f39

Please sign in to comment.