Skip to content

build(deps): update axum to 0.8 and tungstenite and tokio-tungstenite to 0.26 #1305

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

Merged
merged 2 commits into from
Apr 14, 2025
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
142 changes: 20 additions & 122 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 crates/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ workspace = true
[dependencies]
transport = { path = "../transport" }
tokio = { version = "1.44", features = ["io-util"] }
tokio-tungstenite = "0.24"
tokio-tungstenite = "0.26"
futures-util = "0.3"
proptest = "1.5"
anyhow = "1.0"
Expand Down
18 changes: 13 additions & 5 deletions crates/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::collections::HashSet;
use tokio::io::{AsyncRead, AsyncWrite};
use tokio::net::{TcpListener, TcpStream};
use tokio_tungstenite::tungstenite;
use tokio_tungstenite::tungstenite::Bytes;
use transport::ErasedReadWrite;

/// For sane Debug display
Expand Down Expand Up @@ -193,7 +194,7 @@ where
let compat = stream.filter_map(|item| {
let mapped = item
.map(|msg| match msg {
tungstenite::Message::Text(s) => Some(transport::WsReadMsg::Payload(s.into_bytes())),
tungstenite::Message::Text(s) => Some(transport::WsReadMsg::Payload(Bytes::from(s))),
tungstenite::Message::Binary(data) => Some(transport::WsReadMsg::Payload(data)),
tungstenite::Message::Ping(_) | tungstenite::Message::Pong(_) => None,
tungstenite::Message::Close(_) => Some(transport::WsReadMsg::Close),
Expand All @@ -213,8 +214,11 @@ where
{
use futures_util::SinkExt as _;

let compat =
sink.with(|item| futures_util::future::ready(Ok::<_, tungstenite::Error>(tungstenite::Message::Binary(item))));
let compat = sink.with(|item| {
futures_util::future::ready(Ok::<_, tungstenite::Error>(tungstenite::Message::Binary(Bytes::from(
item,
))))
});

transport::WsStream::new(compat)
}
Expand All @@ -233,7 +237,7 @@ where
.filter_map(|item| {
let mapped = item
.map(|msg| match msg {
tungstenite::Message::Text(s) => Some(transport::WsReadMsg::Payload(s.into_bytes())),
tungstenite::Message::Text(s) => Some(transport::WsReadMsg::Payload(Bytes::from(s))),
tungstenite::Message::Binary(data) => Some(transport::WsReadMsg::Payload(data)),
tungstenite::Message::Ping(_) | tungstenite::Message::Pong(_) => None,
tungstenite::Message::Close(_) => Some(transport::WsReadMsg::Close),
Expand All @@ -243,7 +247,11 @@ where

core::future::ready(mapped)
})
.with(|item| futures_util::future::ready(Ok::<_, tungstenite::Error>(tungstenite::Message::Binary(item))));
.with(|item| {
futures_util::future::ready(Ok::<_, tungstenite::Error>(tungstenite::Message::Binary(Bytes::from(
item,
))))
});

transport::WsStream::new(compat)
}
1 change: 1 addition & 0 deletions crates/transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ futures-util = { version = "0.3", features = ["sink"] }
pin-project-lite = "0.2"
parking_lot = "0.12"
tracing = "0.1"
bytes = { version = "1.10", default-features = false }

[dev-dependencies]
futures-util = "0.3"
Expand Down
11 changes: 5 additions & 6 deletions crates/transport/src/ws.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::fmt::Display;
use std::io;
use std::pin::Pin;
use std::task::{Context, Poll};

use bytes::Bytes;
use futures_core::{ready, Stream};
use futures_sink::Sink;
use pin_project_lite::pin_project;
use tokio::io::{AsyncRead, AsyncWrite};

pub enum WsReadMsg {
Payload(Vec<u8>),
Payload(Bytes),
Close,
}

Expand All @@ -18,7 +18,7 @@ pin_project! {
pub struct WsStream<S> {
#[pin]
pub inner: S,
read_buf: Option<Vec<u8>>,
read_buf: Option<Bytes>,
}
}

Expand Down Expand Up @@ -64,11 +64,10 @@ where

// TODO: can we get better performance with `unfilled_mut` and a bit of unsafe code?
let dest = buf.initialize_unfilled_to(bytes_to_copy);
dest.copy_from_slice(&data[..bytes_to_copy]);
dest.copy_from_slice(&data.split_to(bytes_to_copy));
buf.advance(bytes_to_copy);

if data.len() > bytes_to_copy {
data.drain(..bytes_to_copy);
if !data.is_empty() {
*this.read_buf = Some(data);
}

Expand Down
4 changes: 2 additions & 2 deletions crates/video-streamer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ tokio = { version = "1.44", features = [
"macros",
"fs"
] }
axum = { version = "0.7", features = ["ws"] }
axum = { version = "0.8", features = ["ws"] }
futures = "0.3"
tokio-tungstenite = "0.24"
tokio-tungstenite = "0.26"
transport = { path = "../transport" }

[lints]
Expand Down
Loading