Skip to content

Commit 051af68

Browse files
sanityclaude
andauthored
fix: increase WebSocket client message size limit to 100MB (#2252)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a073f30 commit 051af68

File tree

8 files changed

+83
-44
lines changed

8 files changed

+83
-44
lines changed

apps/freenet-ping/app/src/ping_client.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,25 @@ pub async fn wait_for_subscribe_response(
165165
}
166166
}
167167

168+
/// WebSocket configuration with increased message size limit to match server (100MB)
169+
fn ws_config() -> tokio_tungstenite::tungstenite::protocol::WebSocketConfig {
170+
tokio_tungstenite::tungstenite::protocol::WebSocketConfig::default()
171+
.max_message_size(Some(100 * 1024 * 1024)) // 100MB to match server
172+
.max_frame_size(Some(16 * 1024 * 1024)) // 16MB frames
173+
}
174+
168175
// Create a new ping client by connecting to the given host
169176
pub async fn connect_to_host(
170177
host: &str,
171178
) -> Result<WebApi, Box<dyn std::error::Error + Send + Sync + 'static>> {
172179
let uri = format!("ws://{host}/v1/contract/command?encodingProtocol=native");
173-
let (stream, _resp) = tokio_tungstenite::connect_async(&uri).await.map_err(|e| {
174-
tracing::error!(err=%e);
175-
e
176-
})?;
180+
let (stream, _resp) =
181+
tokio_tungstenite::connect_async_with_config(&uri, Some(ws_config()), false)
182+
.await
183+
.map_err(|e| {
184+
tracing::error!(err=%e);
185+
e
186+
})?;
177187
Ok(WebApi::start(stream))
178188
}
179189

apps/freenet-ping/app/tests/common/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use std::{
3131
/// Global lock to prevent concurrent contract compilation which causes race conditions
3232
static COMPILE_LOCK: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
3333
use tokio::{select, time::sleep};
34-
use tokio_tungstenite::connect_async;
34+
pub use tokio_tungstenite::{connect_async_with_config, tungstenite::protocol::WebSocketConfig};
3535
use tracing::{info, span, Instrument, Level};
3636

3737
use serde::{Deserialize, Serialize};
@@ -185,9 +185,16 @@ pub const PATH_TO_CONTRACT: &str = "../contracts/ping";
185185
const WASM_FILE_NAME: &str = "freenet-ping-contract";
186186
pub const APP_TAG: &str = "ping-app";
187187

188+
/// WebSocket configuration with increased message size limit to match server (100MB)
189+
pub fn ws_config() -> WebSocketConfig {
190+
WebSocketConfig::default()
191+
.max_message_size(Some(100 * 1024 * 1024)) // 100MB to match server
192+
.max_frame_size(Some(16 * 1024 * 1024)) // 16MB frames
193+
}
194+
188195
pub async fn connect_ws_client(ws_port: u16) -> Result<WebApi> {
189196
let uri = format!("ws://127.0.0.1:{ws_port}/v1/contract/command?encodingProtocol=native");
190-
let (stream, _) = connect_async(&uri).await?;
197+
let (stream, _) = connect_async_with_config(&uri, Some(ws_config()), false).await?;
191198
Ok(WebApi::start(stream))
192199
}
193200

apps/freenet-ping/app/tests/run_app.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ use futures::{stream::FuturesUnordered, FutureExt, StreamExt};
1616
use rand::SeedableRng;
1717
use testresult::TestResult;
1818
use tokio::{select, time::sleep, time::timeout};
19-
use tokio_tungstenite::connect_async;
2019
use tracing::{span, Instrument, Level};
2120

2221
use common::{
23-
base_node_test_config, base_node_test_config_with_rng, gw_config_from_path,
24-
gw_config_from_path_with_rng, APP_TAG, PACKAGE_DIR, PATH_TO_CONTRACT,
22+
base_node_test_config, base_node_test_config_with_rng, connect_async_with_config,
23+
gw_config_from_path, gw_config_from_path_with_rng, ws_config, APP_TAG, PACKAGE_DIR,
24+
PATH_TO_CONTRACT,
2525
};
2626
use freenet_ping_app::ping_client::{
2727
run_ping_client, wait_for_get_response, wait_for_put_response, wait_for_subscribe_response,
@@ -267,8 +267,9 @@ async fn test_node_diagnostics_query() -> TestResult {
267267
"ws://127.0.0.1:{ws_api_port_node}/v1/contract/command?encodingProtocol=native"
268268
);
269269

270-
let (stream_gw, _) = connect_async(&uri_gw).await?;
271-
let (stream_node, _) = connect_async(&uri_node).await?;
270+
let (stream_gw, _) = connect_async_with_config(&uri_gw, Some(ws_config()), false).await?;
271+
let (stream_node, _) =
272+
connect_async_with_config(&uri_node, Some(ws_config()), false).await?;
272273

273274
let mut client_gw = WebApi::start(stream_gw);
274275
let mut client_node = WebApi::start(stream_node);
@@ -636,9 +637,11 @@ async fn test_ping_multi_node() -> TestResult {
636637
"ws://127.0.0.1:{ws_api_port_node2}/v1/contract/command?encodingProtocol=native"
637638
);
638639

639-
let (stream_gw, _) = connect_async(&uri_gw).await?;
640-
let (stream_node1, _) = connect_async(&uri_node1).await?;
641-
let (stream_node2, _) = connect_async(&uri_node2).await?;
640+
let (stream_gw, _) = connect_async_with_config(&uri_gw, Some(ws_config()), false).await?;
641+
let (stream_node1, _) =
642+
connect_async_with_config(&uri_node1, Some(ws_config()), false).await?;
643+
let (stream_node2, _) =
644+
connect_async_with_config(&uri_node2, Some(ws_config()), false).await?;
642645

643646
let mut client_gw = WebApi::start(stream_gw);
644647
let mut client_node1 = WebApi::start(stream_node1);
@@ -1230,9 +1233,11 @@ async fn test_ping_application_loop() -> TestResult {
12301233
"ws://127.0.0.1:{ws_api_port_node2}/v1/contract/command?encodingProtocol=native"
12311234
);
12321235

1233-
let (stream_gw, _) = connect_async(&uri_gw).await?;
1234-
let (stream_node1, _) = connect_async(&uri_node1).await?;
1235-
let (stream_node2, _) = connect_async(&uri_node2).await?;
1236+
let (stream_gw, _) = connect_async_with_config(&uri_gw, Some(ws_config()), false).await?;
1237+
let (stream_node1, _) =
1238+
connect_async_with_config(&uri_node1, Some(ws_config()), false).await?;
1239+
let (stream_node2, _) =
1240+
connect_async_with_config(&uri_node2, Some(ws_config()), false).await?;
12361241

12371242
let mut client_gw = WebApi::start(stream_gw);
12381243
let mut client_node1 = WebApi::start(stream_node1);
@@ -1718,7 +1723,8 @@ async fn test_ping_partially_connected_network() -> TestResult {
17181723
let uri = format!(
17191724
"ws://127.0.0.1:{port}/v1/contract/command?encodingProtocol=native"
17201725
);
1721-
let (stream, _) = connect_async(&uri).await?;
1726+
let (stream, _) =
1727+
connect_async_with_config(&uri, Some(ws_config()), false).await?;
17221728
let client = WebApi::start(stream);
17231729
gateway_clients.push(client);
17241730
tracing::info!("Connected to gateway {}", i);
@@ -1729,7 +1735,8 @@ async fn test_ping_partially_connected_network() -> TestResult {
17291735
let uri = format!(
17301736
"ws://127.0.0.1:{port}/v1/contract/command?encodingProtocol=native"
17311737
);
1732-
let (stream, _) = connect_async(&uri).await?;
1738+
let (stream, _) =
1739+
connect_async_with_config(&uri, Some(ws_config()), false).await?;
17331740
let client = WebApi::start(stream);
17341741
node_clients.push(client);
17351742
tracing::info!("Connected to regular node {}", i);

apps/freenet-ping/app/tests/run_app_blocked_peers.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ use freenet_stdlib::{
6060
use futures::FutureExt;
6161
use testresult::TestResult;
6262
use tokio::{select, time::sleep};
63-
use tokio_tungstenite::connect_async;
6463
use tracing::{span, Instrument, Level};
6564

65+
use common::{connect_async_with_config, ws_config};
66+
6667
/// Configuration for blocked peers test variants
6768
#[derive(Debug, Clone)]
6869
struct BlockedPeersConfig {
@@ -233,15 +234,17 @@ async fn run_blocked_peers_test(config: BlockedPeersConfig) -> TestResult {
233234
);
234235

235236
tracing::info!("Connecting to Gateway at {}", uri_gw);
236-
let (stream_gw, _) = connect_async(&uri_gw).await?;
237+
let (stream_gw, _) = connect_async_with_config(&uri_gw, Some(ws_config()), false).await?;
237238
let mut client_gw = WebApi::start(stream_gw);
238239

239240
tracing::info!("Connecting to Node1 at {}", uri_node1);
240-
let (stream_node1, _) = connect_async(&uri_node1).await?;
241+
let (stream_node1, _) =
242+
connect_async_with_config(&uri_node1, Some(ws_config()), false).await?;
241243
let mut client_node1 = WebApi::start(stream_node1);
242244

243245
tracing::info!("Connecting to Node2 at {}", uri_node2);
244-
let (stream_node2, _) = connect_async(&uri_node2).await?;
246+
let (stream_node2, _) =
247+
connect_async_with_config(&uri_node2, Some(ws_config()), false).await?;
245248
let mut client_node2 = WebApi::start(stream_node2);
246249

247250
// Compile/load contract code (same helper used by other app tests)

apps/freenet-ping/app/tests/run_app_partially_connected_network.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ use freenet_stdlib::{
2727
use futures::FutureExt;
2828
use testresult::TestResult;
2929
use tokio::{select, time::timeout};
30-
use tokio_tungstenite::connect_async;
3130
use tracing::{span, Instrument, Level};
3231

33-
use common::{base_node_test_config, gw_config_from_path, APP_TAG, PACKAGE_DIR, PATH_TO_CONTRACT};
32+
use common::{
33+
base_node_test_config, connect_async_with_config, gw_config_from_path, ws_config, APP_TAG,
34+
PACKAGE_DIR, PATH_TO_CONTRACT,
35+
};
3436

3537
#[test_log::test(tokio::test(flavor = "multi_thread"))]
3638
#[ignore = "Test has never worked - nodes fail on startup with channel closed errors"]
@@ -236,9 +238,11 @@ async fn test_ping_partially_connected_network() -> TestResult {
236238
let uri = format!(
237239
"ws://127.0.0.1:{port}/v1/contract/command?encodingProtocol=native"
238240
);
239-
let (stream, _) = connect_async(&uri).await.inspect_err(|err| {
240-
println!("Failed to connect to gateway ws {i}: {err}");
241-
})?;
241+
let (stream, _) = connect_async_with_config(&uri, Some(ws_config()), false)
242+
.await
243+
.inspect_err(|err| {
244+
println!("Failed to connect to gateway ws {i}: {err}");
245+
})?;
242246
let client = WebApi::start(stream);
243247
gateway_clients.push(client);
244248
println!("Connected to gateway {i}");
@@ -249,9 +253,11 @@ async fn test_ping_partially_connected_network() -> TestResult {
249253
let uri = format!(
250254
"ws://127.0.0.1:{port}/v1/contract/command?encodingProtocol=native"
251255
);
252-
let (stream, _) = connect_async(&uri).await.inspect_err(|err| {
253-
println!("Failed to connect to regular node ws {i}: {err}");
254-
})?;
256+
let (stream, _) = connect_async_with_config(&uri, Some(ws_config()), false)
257+
.await
258+
.inspect_err(|err| {
259+
println!("Failed to connect to regular node ws {i}: {err}");
260+
})?;
255261
let client = WebApi::start(stream);
256262
node_clients.push(client);
257263
println!("Connected to regular node {i}");

apps/freenet-ping/app/tests/test_50_node_operations.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ use futures::FutureExt;
1919
use std::{net::TcpListener, path::PathBuf, time::Duration};
2020
use testresult::TestResult;
2121
use tokio::{select, time::timeout};
22-
use tokio_tungstenite::connect_async;
2322

24-
use common::{base_node_test_config, gw_config_from_path, APP_TAG, PACKAGE_DIR, PATH_TO_CONTRACT};
23+
use common::{
24+
base_node_test_config, connect_async_with_config, gw_config_from_path, ws_config, APP_TAG,
25+
PACKAGE_DIR, PATH_TO_CONTRACT,
26+
};
2527

2628
const NUM_GATEWAYS: usize = 3; // Multiple gateways to distribute load
2729
const NUM_REGULAR_NODES: usize = 47; // 3 + 47 = 50 total
@@ -216,7 +218,7 @@ async fn setup_50_node_network() -> TestResult<(Vec<WebApi>, Vec<WebApi>, Contra
216218
let mut gateway_clients = Vec::with_capacity(NUM_GATEWAYS);
217219
for (i, port) in ws_api_ports_gw.iter().enumerate() {
218220
let uri = format!("ws://127.0.0.1:{port}/v1/contract/command?encodingProtocol=native");
219-
let (stream, _) = connect_async(&uri).await?;
221+
let (stream, _) = connect_async_with_config(&uri, Some(ws_config()), false).await?;
220222
let client = WebApi::start(stream);
221223
gateway_clients.push(client);
222224
println!("📡 Connected to gateway {i}");
@@ -231,7 +233,7 @@ async fn setup_50_node_network() -> TestResult<(Vec<WebApi>, Vec<WebApi>, Contra
231233
let mut node_clients = Vec::with_capacity(NUM_REGULAR_NODES);
232234
for (i, port) in ws_api_ports_nodes.iter().enumerate() {
233235
let uri = format!("ws://127.0.0.1:{port}/v1/contract/command?encodingProtocol=native");
234-
let (stream, _) = connect_async(&uri).await?;
236+
let (stream, _) = connect_async_with_config(&uri, Some(ws_config()), false).await?;
235237
let client = WebApi::start(stream);
236238
node_clients.push(client);
237239

apps/freenet-ping/app/tests/test_connection_timing.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ use freenet_stdlib::client_api::WebApi;
1111
use futures::FutureExt;
1212
use testresult::TestResult;
1313
use tokio::{select, time::timeout};
14-
use tokio_tungstenite::connect_async;
1514
use tracing::{span, Instrument, Level};
1615

17-
use common::{base_node_test_config, gw_config_from_path};
16+
use common::{base_node_test_config, connect_async_with_config, gw_config_from_path, ws_config};
1817

1918
#[test_log::test(tokio::test(flavor = "multi_thread"))]
2019
async fn test_connection_timing() -> TestResult {
@@ -93,7 +92,7 @@ async fn test_connection_timing() -> TestResult {
9392
let ws_start = Instant::now();
9493
let uri_gw =
9594
format!("ws://127.0.0.1:{ws_api_port_gw}/v1/contract/command?encodingProtocol=native");
96-
let (stream_gw, _) = connect_async(&uri_gw).await?;
95+
let (stream_gw, _) = connect_async_with_config(&uri_gw, Some(ws_config()), false).await?;
9796
let _client_gw = WebApi::start(stream_gw);
9897
println!(
9998
" ✓ Gateway WebSocket connected in {}ms",
@@ -104,7 +103,8 @@ async fn test_connection_timing() -> TestResult {
104103
let uri_node1 = format!(
105104
"ws://127.0.0.1:{ws_api_port_node1}/v1/contract/command?encodingProtocol=native"
106105
);
107-
let (stream_node1, _) = connect_async(&uri_node1).await?;
106+
let (stream_node1, _) =
107+
connect_async_with_config(&uri_node1, Some(ws_config()), false).await?;
108108
let _client_node1 = WebApi::start(stream_node1);
109109
println!(
110110
" ✓ Node1 WebSocket connected in {}ms",

apps/freenet-ping/app/tests/test_small_network_get_issue.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ use freenet_stdlib::{
1212
use futures::FutureExt;
1313
use testresult::TestResult;
1414
use tokio::{select, time::timeout};
15-
use tokio_tungstenite::connect_async;
1615
use tracing::{span, Instrument, Level};
1716

18-
use common::{base_node_test_config, gw_config_from_path, APP_TAG, PACKAGE_DIR, PATH_TO_CONTRACT};
17+
use common::{
18+
base_node_test_config, connect_async_with_config, gw_config_from_path, ws_config, APP_TAG,
19+
PACKAGE_DIR, PATH_TO_CONTRACT,
20+
};
1921

2022
#[test_log::test(tokio::test(flavor = "multi_thread"))]
2123
async fn test_small_network_get_failure() -> TestResult {
@@ -137,19 +139,21 @@ async fn test_small_network_get_failure() -> TestResult {
137139

138140
let uri_gw =
139141
format!("ws://127.0.0.1:{_ws_api_port_gw}/v1/contract/command?encodingProtocol=native");
140-
let (stream_gw, _) = connect_async(&uri_gw).await?;
142+
let (stream_gw, _) = connect_async_with_config(&uri_gw, Some(ws_config()), false).await?;
141143
let mut client_gw = WebApi::start(stream_gw);
142144

143145
let uri_node1 = format!(
144146
"ws://127.0.0.1:{ws_api_port_node1}/v1/contract/command?encodingProtocol=native"
145147
);
146-
let (stream_node1, _) = connect_async(&uri_node1).await?;
148+
let (stream_node1, _) =
149+
connect_async_with_config(&uri_node1, Some(ws_config()), false).await?;
147150
let mut client_node1 = WebApi::start(stream_node1);
148151

149152
let uri_node2 = format!(
150153
"ws://127.0.0.1:{ws_api_port_node2}/v1/contract/command?encodingProtocol=native"
151154
);
152-
let (stream_node2, _) = connect_async(&uri_node2).await?;
155+
let (stream_node2, _) =
156+
connect_async_with_config(&uri_node2, Some(ws_config()), false).await?;
153157
let mut client_node2 = WebApi::start(stream_node2);
154158

155159
let path_to_code = PathBuf::from(PACKAGE_DIR).join(PATH_TO_CONTRACT);

0 commit comments

Comments
 (0)