"Task has lost its waker" and freeze when sending large packets
When sending large packets very quickly, there is a chance the future completely locks up and loses its waker according to `tokio-console` and `console-subscriber`.
I am using `rustc 1.86.0-nightly (1e9b0177d 2025-01-24)`
Reproduction code:
```toml
[package]
name = "tokio-ws-reproduce"
version = "0.1.0"
edition = "2021"
[dependencies]
bytes = "1.9.0"
console-subscriber = "0.4.1"
futures = { version = "0.3.31", default-features = false, features = ["std", "async-await"] }
tokio = { version = "1.43.0", features = ["full"] }
tokio-websockets = { version = "0.11.0", features = ["client", "simd", "sha1_smol", "rand", "native-tls"] }
```
```rust
use bytes::Bytes;
use futures::{SinkExt, StreamExt, future::join};
use tokio_websockets::Message;
#[tokio::main]
async fn main() {
console_subscriber::init();
let (mut tx, mut rx) = tokio_websockets::ClientBuilder::new()
.uri("ws://127.0.0.1:3000")
.unwrap()
.connect()
.await
.unwrap()
.0
.split();
let len = std::env::args().nth(1).unwrap().parse().unwrap();
let a = tokio::spawn(async move {
let x = Bytes::from(vec![0; len]);
let mut cnt = 0usize;
loop {
let x = Message::binary(x.clone());
tx.send(x).await.unwrap();
println!("sent {cnt}");
cnt += 1;
}
});
let b = tokio::spawn(async move {
loop {
rx.next().await;
}
});
join(a, b).await.0.unwrap();
}
```
Run the echo-server example from this repo (commit b8b3418): `cargo r -r --example echo_server -F server,sha1_smol`
Then run the code: `RUSTFLAGS='--cfg tokio_unstable' cargo r -r -- 51205`
On my machine, it locks up after around 100-150 messages with a size of `51205`. It also locks up with smaller message sizes, but not quickly or reliably.
Once it locks up, check tokio-console:


The task location matches up with the `tokio::spawn` for the writer task.
关闭于 2025-01-26 12 条评论