Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add keepalive to Torii client gRPC connections #2690

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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)));

Check warning on line 58 in crates/torii/grpc/src/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/grpc/src/client.rs#L56-L58

Added lines #L56 - L58 were not covered by tests
let channel = endpoint.connect().await.map_err(Error::Transport)?;
Ok(Self {
_world_address: world_address,
Expand Down
Loading