Skip to content
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

Revert "fix(server): return err on WS handshake err (#1288)" #1326

Merged
merged 3 commits into from
Mar 20, 2024
Merged
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
1 change: 1 addition & 0 deletions server/src/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ impl StopHandle {
}
}

/// Error when the server has already been stopped.
#[derive(Debug, Copy, Clone, thiserror::Error)]
#[error("The server is already stopped")]
pub struct AlreadyStoppedError;
Expand Down
16 changes: 8 additions & 8 deletions server/src/transport/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,6 @@ where

match server.receive_request(&req) {
Ok(response) => {
let upgraded = match hyper::upgrade::on(req).await {
Ok(u) => u,
Err(e) => {
tracing::debug!(target: LOG_TARGET, "WS upgrade handshake failed: {}", e);
return Err(hyper::Response::new(hyper::Body::from(format!("WS upgrade handshake failed {e}"))));
}
};

let (tx, rx) = mpsc::channel::<String>(server_cfg.message_buffer_capacity as usize);
let sink = MethodSink::new(tx);

Expand All @@ -448,6 +440,14 @@ where
let rpc_service = rpc_middleware.service(rpc_service);

let fut = async move {
let upgraded = match hyper::upgrade::on(req).await {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yup ok, I have no idea why moving this up would break anything offhand!

Copy link
Member Author

@niklasad1 niklasad1 Mar 21, 2024

Choose a reason for hiding this comment

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

I forgot about https://github.com/hyperium/hyper/blob/master/examples/upgrades.rs#L56-#L72 so it adds up :)

Thus, the http request must be answered before the upgrade can make progress but not super obvious based on the documentation. However good to know why it didn't work :P

Ok(u) => u,
Err(e) => {
tracing::debug!(target: LOG_TARGET, "WS upgrade handshake failed: {}", e);
return;
}
};

let stream = BufReader::new(BufWriter::new(upgraded.compat()));
let mut ws_builder = server.into_builder(stream);
ws_builder.set_max_message_size(server_cfg.max_response_body_size as usize);
Expand Down
Loading