Skip to content

fix: increase WebSocket max message size to 100MB #1677

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "freenet"
version = "0.1.11"
version = "0.1.12"
edition = "2021"
rust-version = "1.80"
publish = true
Expand Down
45 changes: 40 additions & 5 deletions crates/core/src/client_events/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ impl WebSocketProxy {
auth_token,
attested_contract,
} => {
// Log PUT requests for debugging
if let ClientRequest::ContractOp(ContractRequest::Put { contract, .. }) =
req.as_ref()
{
let contract_id = contract.key().to_string();
tracing::info!(
"WebSocketProxy: Processing PUT request from client_id={}, contract_key={}",
client_id,
contract_id
);
}

let open_req = match &*req {
ClientRequest::ContractOp(ContractRequest::Subscribe { key, .. }) => {
tracing::debug!(%client_id, contract = %key, "subscribing to contract");
Expand Down Expand Up @@ -325,7 +337,10 @@ async fn websocket_commands(
}
};

ws.on_upgrade(on_upgrade)
// Increase max message size to 100MB to handle contract uploads
// Default is ~64KB which is too small for WASM contracts
ws.max_message_size(100 * 1024 * 1024)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider this to be a temporal fix, we need to look into different ways of sending messages this large (maybe a regular multipart http request) cause this a bit of an antipattern for ws. I know is over local host but still, we can do better here .

I think eventually we want to stream that right into disk to not hold into such large things in memory for very long, but that requries a bigger architetural change.

.on_upgrade(on_upgrade)
}

async fn websocket_interface(
Expand Down Expand Up @@ -518,17 +533,37 @@ async fn process_client_request(
*auth_token = Some(AuthToken::from(token.clone()));
}

// Add special logging for PUT requests to debug River issue
if let ClientRequest::ContractOp(ContractRequest::Put { contract, .. }) = &req {
let contract_id = contract.key().to_string();
tracing::info!(
"WebSocket: Received PUT request from client_id={}, contract_key={}",
client_id,
contract_id
);
}

tracing::debug!(req = %req, "received client request");
request_sender

let send_result = request_sender
.send(ClientConnection::Request {
client_id,
req: Box::new(req),
auth_token: auth_token.clone(),
attested_contract,
})
.await
.map_err(|err| Some(err.into()))?;
Ok(None)
.await;

match send_result {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the worst part that we were silently swallowing this. In the future we should have a regression test for this forcing some sort of error (it can be done at this component level by mocking the rest of the interface, e.g. dropping the other end of the channel).

good catch

Ok(()) => {
tracing::debug!("Successfully sent client request to handler");
Ok(None)
}
Err(err) => {
tracing::error!("Failed to send client request to handler: {}", err);
Err(Some(err.into()))
}
}
}

async fn process_host_response(
Expand Down
2 changes: 1 addition & 1 deletion crates/fdev/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fdev"
version = "0.1.11"
version = "0.1.12"
edition = "2021"
rust-version = "1.80"
publish = true
Expand Down
Loading