Skip to content

Commit

Permalink
fix: Don't call wake_by_ref in OperatorFuture (#4003)
Browse files Browse the repository at this point in the history
* fix: Don't call wake_by_ref in OperatorFuture

Signed-off-by: Xuanwo <[email protected]>

* Fix dead loop

Signed-off-by: Xuanwo <[email protected]>

* Polish error message

Signed-off-by: Xuanwo <[email protected]>

---------

Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo authored Jan 18, 2024
1 parent 398d17d commit 647eb9b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions core/src/raw/http_util/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
31 changes: 16 additions & 15 deletions core/src/types/operator/operator_futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::Output> {
*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
}
}
}

Expand Down

0 comments on commit 647eb9b

Please sign in to comment.