From 647eb9bb0272a2c06bba2ae8aee710b3f46cdcce Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Thu, 18 Jan 2024 10:54:35 +0800 Subject: [PATCH] fix: Don't call wake_by_ref in OperatorFuture (#4003) * fix: Don't call wake_by_ref in OperatorFuture Signed-off-by: Xuanwo * Fix dead loop Signed-off-by: Xuanwo * Polish error message Signed-off-by: Xuanwo --------- Signed-off-by: Xuanwo --- core/src/raw/http_util/client.rs | 4 +-- core/src/types/operator/operator_futures.rs | 31 +++++++++++---------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/core/src/raw/http_util/client.rs b/core/src/raw/http_util/client.rs index f83c18840985..2c5e4bc5c78b 100644 --- a/core/src/raw/http_util/client.rs +++ b/core/src/raw/http_util/client.rs @@ -156,8 +156,8 @@ impl HttpClient { err.is_status() ); - let mut oerr = Error::new(ErrorKind::Unexpected, "send async request") - .with_operation("http_util::Client::send_async") + let mut oerr = Error::new(ErrorKind::Unexpected, "send http request") + .with_operation("http_util::Client::send") .with_context("url", uri.to_string()) .set_source(err); if is_temporary { diff --git a/core/src/types/operator/operator_futures.rs b/core/src/types/operator/operator_futures.rs index 4faf5ea52301..fda23d1dff0c 100644 --- a/core/src/types/operator/operator_futures.rs +++ b/core/src/types/operator/operator_futures.rs @@ -95,22 +95,23 @@ where /// /// In general, `Empty` state should not be polled. fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - *self = match mem::replace(self.as_mut().get_mut(), OperatorFuture::Empty) { - OperatorFuture::Idle(inner, path, args, f) => { - // Wake up to make sure the future is ready after the - // future has been built. - cx.waker().wake_by_ref(); - OperatorFuture::Poll(f(inner, path, args)) + loop { + match mem::replace(self.as_mut().get_mut(), OperatorFuture::Empty) { + OperatorFuture::Idle(inner, path, args, f) => { + *self = OperatorFuture::Poll(f(inner, path, args)) + } + OperatorFuture::Poll(mut fut) => match fut.as_mut().poll(cx) { + Poll::Ready(v) => return Poll::Ready(v), + Poll::Pending => { + *self = OperatorFuture::Poll(fut); + return Poll::Pending; + } + }, + OperatorFuture::Empty => { + panic!("future polled after completion"); + } } - OperatorFuture::Poll(mut fut) => match fut.as_mut().poll(cx) { - Poll::Pending => OperatorFuture::Poll(fut), - Poll::Ready(v) => return Poll::Ready(v), - }, - OperatorFuture::Empty => { - panic!("future polled after completion"); - } - }; - Poll::Pending + } } }