Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added keepalive timout so that connections are not dropped.
Browse files Browse the repository at this point in the history
christos-h committed Oct 31, 2024
1 parent c88f42a commit b298a84
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions linera-rpc/src/grpc/mod.rs
Original file line number Diff line number Diff line change
@@ -47,3 +47,8 @@ pub const GRPC_MAX_MESSAGE_SIZE: usize = 16 * MEBIBYTE;
/// Limit of gRPC message size up to which we will try to populate with data when estimating.
/// We leave 30% of buffer for the rest of the message and potential underestimation.
pub const GRPC_CHUNKED_MESSAGE_FILL_LIMIT: usize = GRPC_MAX_MESSAGE_SIZE * 7 / 10;

/// https://grpc.io/docs/guides/keepalive/#keepalive-configuration-specification
/// This is hard-coded for now. In future implementations it should be negotiated
/// between client and server.
pub const KEEPALIVE_TIME_MS: u64 = 40 * 1000;
4 changes: 3 additions & 1 deletion linera-rpc/src/grpc/transport.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright (c) Zefchain Labs, Inc.

Check warning on line 1 in linera-rpc/src/grpc/transport.rs

GitHub Actions / lint

Diff in /home/runner/work/linera-protocol/linera-protocol/linera-rpc/src/grpc/transport.rs
// SPDX-License-Identifier: Apache-2.0

use crate::NodeOptions;
use crate::{grpc::KEEPALIVE_TIME_MS, NodeOptions};

Check failure on line 4 in linera-rpc/src/grpc/transport.rs

GitHub Actions / web

unused import: `grpc::KEEPALIVE_TIME_MS`
use std::time::Duration;

Check failure on line 5 in linera-rpc/src/grpc/transport.rs

GitHub Actions / web

unused import: `std::time::Duration`

#[derive(Clone, Debug, Default)]
pub struct Options {
@@ -42,6 +43,7 @@ cfg_if::cfg_if! {
if let Some(timeout) = options.timeout {
endpoint = endpoint.timeout(timeout);
}
endpoint = endpoint.keep_alive_timeout(Duration::from_millis(KEEPALIVE_TIME_MS));
Ok(endpoint.connect_lazy())
}
}

0 comments on commit b298a84

Please sign in to comment.