Skip to content

Commit 85dcced

Browse files
authored
increase max websocket frame size (#1585)
* fix frame size bug * revisions - make the max frame size customizable
1 parent d3d9fa8 commit 85dcced

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

client/transport/src/ws/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ pub struct WsTransportClientBuilder {
9595
pub max_request_size: u32,
9696
/// Max response payload size
9797
pub max_response_size: u32,
98+
/// Max frame size
99+
pub max_frame_size: Option<u32>,
98100
/// Max number of redirections.
99101
pub max_redirections: usize,
100102
/// TCP no delay.
@@ -108,6 +110,7 @@ impl Default for WsTransportClientBuilder {
108110
certificate_store: CertificateStore::Native,
109111
max_request_size: TEN_MB_SIZE_BYTES,
110112
max_response_size: TEN_MB_SIZE_BYTES,
113+
max_frame_size: None,
111114
connection_timeout: Duration::from_secs(10),
112115
headers: http::HeaderMap::new(),
113116
max_redirections: 5,
@@ -140,6 +143,12 @@ impl WsTransportClientBuilder {
140143
self
141144
}
142145

146+
/// Set the maximum size of a frame in bytes (default is none).
147+
pub fn max_frame_size(mut self, size: u32) -> Self {
148+
self.max_frame_size = Some(size);
149+
self
150+
}
151+
143152
/// Set connection timeout for the handshake (default is 10 seconds).
144153
pub fn connection_timeout(mut self, timeout: Duration) -> Self {
145154
self.connection_timeout = timeout;
@@ -498,6 +507,10 @@ impl WsTransportClientBuilder {
498507
tracing::debug!(target: LOG_TARGET, "Connection established to target: {:?}", target);
499508
let mut builder = client.into_builder();
500509
builder.set_max_message_size(self.max_response_size as usize);
510+
// Use the max frame size if any, otherwise let the underlying code use appropriate defaults.
511+
if let Some(max_frame_size) = self.max_frame_size {
512+
builder.set_max_frame_size(max_frame_size as usize);
513+
}
501514
let (sender, receiver) = builder.finish();
502515
Ok((Sender { inner: sender, max_request_size: self.max_request_size }, Receiver { inner: receiver }))
503516
}

client/ws-client/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ pub struct WsClientBuilder<RpcMiddleware = Logger> {
9191
certificate_store: CertificateStore,
9292
max_request_size: u32,
9393
max_response_size: u32,
94+
max_frame_size: Option<u32>,
9495
request_timeout: Duration,
9596
connection_timeout: Duration,
9697
ping_config: Option<PingConfig>,
@@ -110,6 +111,7 @@ impl Default for WsClientBuilder {
110111
certificate_store: CertificateStore::Native,
111112
max_request_size: TEN_MB_SIZE_BYTES,
112113
max_response_size: TEN_MB_SIZE_BYTES,
114+
max_frame_size: None,
113115
request_timeout: Duration::from_secs(60),
114116
connection_timeout: Duration::from_secs(10),
115117
ping_config: None,
@@ -212,6 +214,12 @@ impl<RpcMiddleware> WsClientBuilder<RpcMiddleware> {
212214
self
213215
}
214216

217+
/// See documentation [`WsTransportClientBuilder::max_frame_size`] (default is none).
218+
pub fn max_frame_size(mut self, size: u32) -> Self {
219+
self.max_frame_size = Some(size);
220+
self
221+
}
222+
215223
/// See documentation [`ClientBuilder::request_timeout`] (default is 60 seconds).
216224
pub fn request_timeout(mut self, timeout: Duration) -> Self {
217225
self.request_timeout = timeout;
@@ -279,6 +287,7 @@ impl<RpcMiddleware> WsClientBuilder<RpcMiddleware> {
279287
certificate_store: self.certificate_store,
280288
max_request_size: self.max_request_size,
281289
max_response_size: self.max_response_size,
290+
max_frame_size: self.max_frame_size,
282291
request_timeout: self.request_timeout,
283292
connection_timeout: self.connection_timeout,
284293
ping_config: self.ping_config,
@@ -346,6 +355,7 @@ impl<RpcMiddleware> WsClientBuilder<RpcMiddleware> {
346355
headers: self.headers.clone(),
347356
max_request_size: self.max_request_size,
348357
max_response_size: self.max_response_size,
358+
max_frame_size: self.max_frame_size,
349359
max_redirections: self.max_redirections,
350360
tcp_no_delay: self.tcp_no_delay,
351361
};
@@ -375,6 +385,7 @@ impl<RpcMiddleware> WsClientBuilder<RpcMiddleware> {
375385
headers: self.headers.clone(),
376386
max_request_size: self.max_request_size,
377387
max_response_size: self.max_response_size,
388+
max_frame_size: self.max_frame_size,
378389
max_redirections: self.max_redirections,
379390
tcp_no_delay: self.tcp_no_delay,
380391
};

0 commit comments

Comments
 (0)