diff --git a/client/src/lib.rs b/client/src/lib.rs index 56caab05b2..35b0eabaf4 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -217,10 +217,11 @@ impl Client { } } else if let Some(err) = self.postbox.error() { return Err(err.into()); - } else if self.state.get_time() - self.last_ping > SERVER_TIMEOUT * 0.5 { - self.postbox.send(ClientMsg::Ping); } else if self.state.get_time() - self.last_ping > SERVER_TIMEOUT { return Err(Error::ServerTimeout); + } else if self.state.get_time() - self.last_ping > SERVER_TIMEOUT * 0.5 { + // Try pinging the server if the timeout is nearing + self.postbox.send(ClientMsg::Ping); } Ok(frontend_events) diff --git a/server/src/lib.rs b/server/src/lib.rs index 9d76514eb7..867d4b1b6b 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -204,6 +204,9 @@ impl Server { client.postbox.error().is_some() // Postbox error { disconnected = true; + } else if state.get_time() - client.last_ping > CLIENT_TIMEOUT * 0.5 { + // Try pinging the client if the timeout is nearing + client.postbox.send(ServerMsg::Ping); } if disconnected {