Skip to content

Commit

Permalink
feat: add keepalive to Torii client gRPC connections (#2690)
Browse files Browse the repository at this point in the history
* add keepalive to WorldClient

* Remove keepalive argument from Torii client and set keep alive to default 30 secs

* Introduce constant for keepalive time + set to 60 secs as per recommended
  • Loading branch information
edisontim authored Nov 14, 2024
1 parent a8cea6f commit eecd8bf
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/torii/grpc/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Client implementation for the gRPC service.
use std::num::ParseIntError;
use std::time::Duration;

use futures_util::stream::MapOk;
use futures_util::{Stream, StreamExt, TryStreamExt};
Expand Down Expand Up @@ -50,8 +51,11 @@ pub struct WorldClient {
impl WorldClient {
#[cfg(not(target_arch = "wasm32"))]
pub async fn new(dst: String, world_address: Felt) -> Result<Self, Error> {
let endpoint =
Endpoint::from_shared(dst.clone()).map_err(|e| Error::Endpoint(e.to_string()))?;
const KEEPALIVE_TIME: u64 = 60;

let endpoint = Endpoint::from_shared(dst.clone())
.map_err(|e| Error::Endpoint(e.to_string()))?
.tcp_keepalive(Some(Duration::from_secs(KEEPALIVE_TIME)));
let channel = endpoint.connect().await.map_err(Error::Transport)?;
Ok(Self {
_world_address: world_address,
Expand Down

0 comments on commit eecd8bf

Please sign in to comment.