Skip to content

Commit

Permalink
fix: Tokio runtime panic when using QuinnListener (#819)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislearn committed Jun 24, 2024
1 parent 2df4f6d commit d86c70c
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions crates/core/src/http/body/req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ cfg_feature! {
pub(crate) mod h3 {
use std::boxed::Box;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::task::{ready, Context, Poll};

use hyper::body::{Body, Frame, SizeHint};
use salvo_http3::quic::RecvStream;
Expand Down Expand Up @@ -255,20 +255,16 @@ cfg_feature! {

fn poll_frame(
mut self: Pin<&mut Self>,
_cx: &mut Context<'_>,
cx: &mut Context<'_>,
) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>> {
let this = &mut *self;
let rt = tokio::runtime::Runtime::new().expect("create tokio runtime failed");
// TODO: how to remove block?
Poll::Ready(Some(rt.block_on(async move {
match this.inner.recv_data().await {
Ok(Some(buf)) => {
Ok(Frame::data(Bytes::copy_from_slice(buf.chunk())))
}
Ok(None) => Ok(Frame::data(Bytes::new())),
Err(e) => Err(e.into()),
match ready!(this.inner.poll_recv_data(cx)) {
Ok(Some(buf)) => {
Poll::Ready(Some(Ok(Frame::data(Bytes::copy_from_slice(buf.chunk())))))
}
})))
Ok(None) => Poll::Ready(None),
Err(e) => Poll::Ready(Some(Err(e.into()))),
}
}

fn is_end_stream(&self) -> bool {
Expand Down

0 comments on commit d86c70c

Please sign in to comment.