Skip to content

Commit

Permalink
frame size should be >= max response size
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed May 21, 2024
1 parent 69252f3 commit 5d9e060
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions comms/core/src/protocol/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mod test;

/// Maximum frame size of each RPC message. This is enforced in tokio's length delimited codec.
/// This can be thought of as the hard limit on message size.
pub const RPC_MAX_FRAME_SIZE: usize = 3 * 1024 * 1024; // 3 MiB
pub const RPC_MAX_FRAME_SIZE: usize = 4 * 1024 * 1024; // 4 MiB
/// The maximum size for a single RPC response message
pub const RPC_MAX_RESPONSE_SIZE: usize = 4 * 1024 * 1024; // 4 MiB

Expand All @@ -39,15 +39,15 @@ const fn max_request_size() -> usize {
RPC_MAX_FRAME_SIZE
}

/// The maximum size for a single RPC response excluding overhead
/// The maximum size for a single RPC response body excluding response header overhead
const fn max_response_payload_size() -> usize {
// RpcResponse overhead is:
// - 4 varint protobuf fields, each field ID is 1 byte
// - 3 u32 fields, VarInt(u32::MAX) is 5 bytes
// - 1 length varint for the payload, allow for 5 bytes to be safe (max_payload_size being technically too small is
// fine, being too large isn't)
const MAX_HEADER_SIZE: usize = 4 + 4 * 5;
RPC_MAX_RESPONSE_SIZE - MAX_HEADER_SIZE
RPC_MAX_FRAME_SIZE - MAX_HEADER_SIZE
}

mod body;
Expand Down
3 changes: 2 additions & 1 deletion comms/core/src/protocol/rpc/test/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,11 @@ async fn concurrent_requests() {

#[tokio::test]
async fn response_too_big() {
env_logger::builder().filter_level(log::LevelFilter::Debug).init();
let (_inbound, outbound, _, _, _shutdown) = setup(GreetingService::new(&[]), 1).await;
let socket = outbound.get_yamux_control().open_stream().await.unwrap();

let framed = framing::canonical(socket, rpc::RPC_MAX_RESPONSE_SIZE);
let framed = framing::canonical(socket, rpc::max_request_size());
let mut client = GreetingClient::builder()
.with_deadline(Duration::from_secs(5))
.connect(framed)
Expand Down

0 comments on commit 5d9e060

Please sign in to comment.