Closed markcda closed 2 weeks ago
Can you run the hello-h3 example normally? From the error, it seems that you have blocked the main thread of tokio, which is a problem with your code.
Can you run the hello-h3 example normally? From the error, it seems that you have blocked the main thread of tokio, which is a problem with your code.
Well, hello-h3
runs normally.
With log's help I found that the bug is rising when I try parse JSON from request (let data = req.parse_json::<MyData>().await?;
Please provide the minimal reproducible code。
main.rs
:
use salvo::conn::rustls::{Keycert, RustlsConfig};
use salvo::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct SignInRequestData {
pub login: String,
pub password: String,
}
#[handler]
async fn login(req: &mut Request, res: &mut Response) {
let data = req.parse_json::<SignInRequestData>().await.unwrap();
res.render(format!("Logged in as {}", data.login));
}
#[tokio::main]
async fn main() {
tracing_subscriber::fmt().init();
let cert = include_bytes!("../certs/cert.pem").to_vec();
let key = include_bytes!("../certs/key.pem").to_vec();
let router = Router::new().post(login);
let config = RustlsConfig::new(Keycert::new().cert(cert.as_slice()).key(key.as_slice()));
let listener = TcpListener::new(("0.0.0.0", 5800)).rustls(config.clone());
let acceptor = QuinnListener::new(config.build_quinn_config().unwrap(), ("0.0.0.0", 5800))
.join(listener)
.bind()
.await;
Server::new(acceptor).serve(router).await;
}
Cargo.toml
:
[package]
name = "example-hello-h3"
version.workspace = true
edition.workspace = true
publish.workspace = true
[dependencies]
salvo = { workspace = true, features = ["quinn"] }
serde = { version = "1", features = ["derive"] }
tokio = { workspace = true, features = ["macros"] }
tracing.workspace = true
tracing-subscriber.workspace = true
cd examples && cargo run --bin example-hello-h3
And doing request with curl:
curl --request POST --http3-only --tlsv1.3 -H "Content-Type: application/json" --data '{"login":"xyz","password":"xyz"}' https://localhost:5800 --verbose
We're getting:
* upload completely sent off: 32 bytes
* HTTP/3 stream 0 was closed cleanly, but before getting all response header fields, treated as error
* Connection #0 to host localhost left intact
curl: (95) error:8000006F:system library::Connection refused
And:
thread 'tokio-runtime-worker' panicked at /home/titoffklim/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.38.0/src/runtime/scheduler/multi_thread/mod.rs:86:9:
Cannot start a runtime from within a runtime. This happens because a function (like `block_on`) attempted to block the current thread while the thread is being used to drive asynchronous tasks.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
As long as HTTP/2 connection looks like this:
curl --request POST -H "Content-Type: application/json" --data '{"login":"xyz","password":"xyz"}' https://localhost:5800 --verbose
< HTTP/2 200
< alt-svc: h3=":5800"; ma=2592000,h3-29=":5800"; ma=2592000
< content-type: text/plain; charset=utf-8
< date: Mon, 24 Jun 2024 06:36:56 GMT
< content-length: 16
<
* Connection #0 to host localhost left intact
Logged in as xyz
Describe the bug
thread 'tokio-runtime-worker' panicked
To Reproduce Steps to reproduce the behavior:
With
RUST_BACKTRACE=full
still found not so much useful information:Expected behavior Handler should be executed. At least, it works as expected when using HTTP/2, HTTP/1.1.
Desktop (please complete the following information):