Skip to content
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

fix(transport): return Poll::ready until error is consumed #495

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion tonic/src/transport/service/reconnect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use tracing::trace;
pub(crate) struct Reconnect<M, Target>
where
M: Service<Target>,
M::Error: Into<Error>,
{
mk_service: M,
state: State<M::Future, M::Response>,
Expand All @@ -32,6 +33,7 @@ enum State<F, S> {
impl<M, Target> Reconnect<M, Target>
where
M: Service<Target>,
M::Error: Into<Error>,
{
pub(crate) fn new(mk_service: M, target: Target, is_lazy: bool) -> Self {
Reconnect {
Expand All @@ -52,6 +54,7 @@ where
M::Future: Unpin,
Error: From<M::Error> + From<S::Error>,
Target: Clone,
<M as tower_service::Service<Target>>::Error: fmt::Debug,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be Into<Error> or else it might break the stack down the line.

{
type Response = S::Response;
type Error = Error;
Expand All @@ -60,6 +63,10 @@ where
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
let mut state;

if self.error.is_some() {
return Poll::Ready(Ok(()));
}

loop {
match self.state {
State::Idle => {
Expand Down Expand Up @@ -94,7 +101,9 @@ where
if !(self.has_been_connected || self.is_lazy) {
return Poll::Ready(Err(e.into()));
} else {
self.error = Some(e);
let error = e.into();
tracing::error!("reconnect::poll_ready: {:?}", error);
self.error = Some(error);
break;
}
}
Expand Down Expand Up @@ -130,7 +139,9 @@ where
}

fn call(&mut self, request: Request) -> Self::Future {
tracing::trace!("Reconnect::call");
if let Some(error) = self.error.take() {
tracing::error!("error: {:?}", error);
return ResponseFuture::error(error);
}

Expand All @@ -150,6 +161,7 @@ where
M::Future: fmt::Debug,
M::Response: fmt::Debug,
Target: fmt::Debug,
<M as tower_service::Service<Target>>::Error: Into<Error>,
{
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Reconnect")
Expand Down