-
Notifications
You must be signed in to change notification settings - Fork 31
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
looping over RecvStream::read causes an infinite loop without the client sending anything. #176
Comments
I discovered something new here, in the client code, await stream.close(); promise never resolves or rejects for some reason. wt.close() is never closed. although i can't tell for sure, because I don't know the implementation details, i just deduced from what i saw. Edit: after testing a few more times, i noticed that this also happens with |
If you are trying to reproduce this, please know that this does not occur every time. I refreshed the page multiple (8-12) times making connections multiple times and it happened only once. |
Maybe the js stream is locked by the writer? https://developer.mozilla.org/en-US/docs/Web/API/WritableStream/locked |
@BiagioFesta the js stream is locked because i am writing to the stream, but how does that cause these issues... |
@JimitSoni18 can you please explain better what the issue exactly and what is the behavior that instead you expect? I don't see any "stuck loop" trying your code. If are you referring that |
I have attached a video that shows how the RecvStream::read returns continuously without the client sending any data. you can also see that this does not happen every time i start a connection. use std::time::Duration;
use wtransport::{Endpoint, Identity, ServerConfig};
#[tokio::main]
async fn main() {
let config = ServerConfig::builder()
.with_bind_default(4433)
.with_identity(
&Identity::load_pemfiles(
"/home/jimit/certs/full-chain.cert.pem",
"/home/jimit/certs/private.key.pem",
)
.await
.unwrap(),
)
.max_idle_timeout(Some(Duration::from_secs(20)))
.unwrap()
.build();
let server = Endpoint::server(config).unwrap();
loop {
let incoming_session = server.accept().await;
println!("incoming session");
match incoming_session.await {
Ok(incoming_request) => {
let connection_result = incoming_request.accept().await;
println!(
"ok request type of connection: {}",
if connection_result.is_ok() {
"Ok"
} else {
"Err"
}
);
match connection_result {
Ok(connection) => {
tokio::spawn(handle_connection(connection));
}
Err(error) => {
eprintln!("rejected connection for reason: {error}");
}
}
}
Err(error) => {
eprintln!("=>> {error:?}\n");
continue;
}
};
}
}
async fn handle_connection(connection: wtransport::Connection) {
match connection.accept_uni().await {
Ok(mut uni_stream) => {
let mut bytes = vec![0; 256];
loop {
match uni_stream.read(&mut bytes).await {
Ok(result) => {
if let Some(size) = result {
println!("read {size} bytes");
let res_string = String::from_utf8(
bytes[0..size].to_vec().clone(),
);
if let Ok(message) = res_string {
println!("{message}");
} else {
println!("{res_string:?}");
}
} else {
println!("read nothing");
}
}
Err(error) => {
eprintln!("error reading bytes: {error}");
return;
}
}
}
}
Err(error) => {
eprintln!("uni_stream returned error: {error}");
}
}
println!("returning for whatever reason");
} Expected behavior:in the const wt = new WebTransport("https://127.0.0.1:4433");
console.log({ wt });
await wt.ready;
const buffer1 = new TextEncoder().encode(
"Hello from the other siiiiiiddeee."
);
const buffer2 = new TextEncoder().encode(
"I must have tried a thousand tiiiiiimeeeess"
);
const stream = await wt.createUnidirectionalStream();
const writer = stream.getWriter();
await writer.write(buffer1);
await writer.write(buffer2);
await writer.ready; Please tell me if there is any confusion |
forgot to attach the video |
Thank you for the attached video, that makes the investigation always easier :) There are a few notes:
|
@BiagioFesta that makes sense! i'll use tracing for the logging issue, but I also have some more questions:
|
It depends what connection that log belongs to.
Again, that might be a previous connection. The log might appear after some time because timeout of browser collecting the connection.
I don't know. That feels strange to me. More investigation is needed.
I am not sure I am understanding this point here. The stream is polled when data is available. When it returns |
i have the following server code that loops over received message on RecvStream::read :
and the following client code:
and here are the logs of both client and server (in screenshot):
as you can see, i am only sending data once on the stream, but it still gets stuck in loop for whatever reason.
the fault could completely be mine here, as i haven't used webtransport a lot and know nothing about how streams work, so i do appreciate any feedback, thank you!
The text was updated successfully, but these errors were encountered: