Skip to content

Commit

Permalink
Fix disconnecting players that never acknowledge an update
Browse files Browse the repository at this point in the history
  • Loading branch information
vladbat00 committed Jan 23, 2023
1 parent e1957f4 commit 77bc001
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions libs/server_lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ mod net;
mod persistence;
mod player_updates;

pub const DEFAULT_IDLE_TIMEOUT: u64 = 300_000;
pub const DEFAULT_IDLE_TIMEOUT_MILLIS: u64 = 300_000;

#[derive(Resource)]
pub struct Agones {
Expand Down Expand Up @@ -209,9 +209,9 @@ impl Plugin for MuddleServerPlugin {
.unwrap_or_else(|| {
log::info!(
"Using the default value for MUDDLE_IDLE_TIMEOUT: {}",
DEFAULT_IDLE_TIMEOUT
DEFAULT_IDLE_TIMEOUT_MILLIS
);
Duration::from_millis(DEFAULT_IDLE_TIMEOUT)
Duration::from_millis(DEFAULT_IDLE_TIMEOUT_MILLIS)
}),
)
});
Expand Down
8 changes: 4 additions & 4 deletions libs/server_lib/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ pub fn process_network_events(
if let Err(err) = connection_state
.apply_outgoing_acknowledgements(frame_number, ack_bit_set)
{
log::debug!(
log::trace!(
"Failed to apply outgoing packet acknowledgments (player: {}, update frame: {}, current frame: {}): {:?}",
player_net_id.0,
update.frame_number,
Expand Down Expand Up @@ -717,7 +717,7 @@ fn disconnect_players(
.set_status(ConnectionStatus::Disconnecting(DisconnectReason::Timeout));
}
} else if Instant::now().duration_since(connection_state.status_updated_at())
> Duration::from_secs(CONNECTION_TIMEOUT_MILLIS)
> Duration::from_millis(CONNECTION_TIMEOUT_MILLIS)
{
// Disconnect players that haven't sent any updates at all (they are likely
// in the `Connecting` or `Handshaking` status) if they are staying in this
Expand All @@ -729,7 +729,7 @@ fn disconnect_players(
// Disconnecting players that haven't sent any message for
// `CONNECTION_TIMEOUT_MILLIS`.
if Instant::now().duration_since(connection_state.last_valid_message_received_at)
> Duration::from_secs(CONNECTION_TIMEOUT_MILLIS)
> Duration::from_millis(CONNECTION_TIMEOUT_MILLIS)
{
log::warn!("Disconnecting {}: idle", handle);
connection_state.set_status(ConnectionStatus::Disconnecting(DisconnectReason::Timeout));
Expand Down Expand Up @@ -1169,7 +1169,7 @@ fn create_player_state(
.get_with_extrapolation(updates_start_frame)
.map(|(_frame_number, direction)| *direction)
.unwrap_or_else(|| {
log::debug!(
log::trace!(
"Missing updates for Player {} (updates start frame: {}, last player direction frame: {:?})",
net_id.0,
updates_start_frame,
Expand Down
2 changes: 1 addition & 1 deletion libs/shared_lib/src/framebuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl<T> Framebuffer<Option<T>> {
)
});
if result.is_none() {
log::warn!(
log::trace!(
"No value found to extrapolate for frame {} (start_frame: {}, limit: {})",
frame_number.value(),
self.start_frame.value(),
Expand Down
10 changes: 5 additions & 5 deletions libs/utils_lib/src/jwks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use reqwest::Url;
use serde::{Deserialize, Serialize};
use std::{convert::TryFrom, time::Duration};

pub const DEFAULT_JWK_CACHE_TTL: u64 = 15;
pub const DEFAULT_JWK_CACHE_TTL_SECS: u64 = 15;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct JwkSet<'a> {
Expand Down Expand Up @@ -131,10 +131,10 @@ pub async fn poll_jwks(client: reqwest::Client, certs_url: Url, jwks: Jwks) {
let jwk_ttl = max_age.unwrap_or_else(|err| {
log::error!(
"Unable to determine cache TTL (will invalidate in {} seconds): {:?}",
DEFAULT_JWK_CACHE_TTL,
DEFAULT_JWK_CACHE_TTL_SECS,
err
);
Duration::from_secs(DEFAULT_JWK_CACHE_TTL)
Duration::from_secs(DEFAULT_JWK_CACHE_TTL_SECS)
});

match response.json::<JwkSet>().await {
Expand Down Expand Up @@ -162,10 +162,10 @@ pub async fn poll_jwks(client: reqwest::Client, certs_url: Url, jwks: Jwks) {
Err(err) => {
log::error!(
"Failed to fetch JwtSet (will re-try in {} seconds): {:?}",
DEFAULT_JWK_CACHE_TTL,
DEFAULT_JWK_CACHE_TTL_SECS,
err
);
Duration::from_secs(DEFAULT_JWK_CACHE_TTL)
Duration::from_secs(DEFAULT_JWK_CACHE_TTL_SECS)
}
};

Expand Down

0 comments on commit 77bc001

Please sign in to comment.