Don't make buffer::Worker block the reactor (#133)

Previously, `tower_buffer::Worker` would continue to loop indefinitely,
even if both the incoming request stream and the service returned
`NotReady`, starving the reactor in the process.
This commit is contained in:
Jon Gjengset 2018-12-06 13:10:10 -05:00 committed by GitHub
parent 6377702087
commit c1b96616b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -446,6 +446,22 @@ where
if let Async::Ready(()) = self.service.poll_service().map_err(|_| ())? {
// Note to future iterations that there's no reason to call poll_service.
any_outstanding = false;
} else {
// The service can't make any more progress.
// Let's see how we can have gotten here:
//
// - If poll_next_msg returned NotReady, we should return NotReady.
// - If poll_next_msg returned Ready(None), we'd have self.finish = true,
// but we're in the else clause, so that can't be the case.
// - If poll_next_msg returned Ready(Some) and poll_ready() returned NotReady,
// we should return NotReady here as well, since the service can't make
// progress yet to accept the message.
// - If poll_next_msg returned Ready(Some) and poll_ready() returned Ready,
// we'd have continued, so that can't be the case.
//
// Thus, in all cases when we get to this point, we should return NotReady.
// So:
return Ok(Async::NotReady);
}
}
}