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

Upgrade tokio-tungstenite #1046

Merged
merged 1 commit into from
Oct 2, 2023
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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/libs/ml2_mods/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ tokio = { version = "1.32", features = [
"tracing",
] }
tokio-graceful-shutdown = "0.13"
tokio-tungstenite = { version = "0.19", features = ["native-tls"] }
tokio-tungstenite = { version = "0.20", features = ["native-tls"] }
tower = { version = "0.4", features = ["util"] }
tracing = "0.1"
zip = "0.6"
Expand Down
12 changes: 4 additions & 8 deletions src/libs/ml2_mods/src/spelunkyfyi/web_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,8 @@ impl WebSocketClient {
.header(SEC_WEBSOCKET_KEY, generate_key())
.body(())?;

// This is the maximum number of messages that will be queued in Tungstenite. This doesn't
// include pong or close messages. All messages are buffered before they're written. So,
// the smallest functional value is 1. Notably, the size of the messages and the underlying
// TCP send buffer aren't considered.
let config = WebSocketConfig {
max_send_queue: Some(2),
..Default::default()
};
let mut config = WebSocketConfig::default();
config.max_write_buffer_size = 2 * config.write_buffer_size;

let mut stream = tokio_tungstenite::connect_async_with_config(request, Some(config), false)
.await
Expand Down Expand Up @@ -163,6 +157,7 @@ impl WebSocketClient {
stream
.send(Message::Ping(payload))
.await?;
stream.flush().await?;
check_state = Check::Pong();
check_sleep = Box::pin(time::sleep(self.pong_timeout));
}
Expand Down Expand Up @@ -312,6 +307,7 @@ async fn send_message(
) -> Result<(), ConnectionError> {
let reply = serde_json::to_string(&msg)?;
stream.send(Message::Text(reply)).await?;
stream.flush().await?;
Ok(())
}

Expand Down