diff --git a/CHANGES.md b/CHANGES.md index db938c937..fd7f0e2db 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,8 @@ * Added error response functions for 501,502,503,504 +* Fix client request timeout handling + ## 0.6.2 (2018-05-09) diff --git a/src/client/mod.rs b/src/client/mod.rs index 436fcf206..2116ae360 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -49,6 +49,7 @@ use httpresponse::HttpResponse; impl ResponseError for SendRequestError { fn error_response(&self) -> HttpResponse { match *self { + SendRequestError::Timeout => HttpResponse::GatewayTimeout(), SendRequestError::Connector(_) => HttpResponse::BadGateway(), _ => HttpResponse::InternalServerError(), }.into() diff --git a/src/client/pipeline.rs b/src/client/pipeline.rs index 60eb4f8c2..6a36bdd23 100644 --- a/src/client/pipeline.rs +++ b/src/client/pipeline.rs @@ -194,6 +194,7 @@ impl Future for SendRequest { self.state = State::Send(pl); } State::Send(mut pl) => { + pl.poll_timeout()?; pl.poll_write().map_err(|e| { io::Error::new(io::ErrorKind::Other, format!("{}", e).as_str()) })?; @@ -315,7 +316,7 @@ impl Pipeline { { Async::NotReady => need_run = true, Async::Ready(_) => { - let _ = self.poll_timeout().map_err(|e| { + self.poll_timeout().map_err(|e| { io::Error::new(io::ErrorKind::Other, format!("{}", e)) })?; } @@ -371,16 +372,15 @@ impl Pipeline { } } - fn poll_timeout(&mut self) -> Poll<(), SendRequestError> { + fn poll_timeout(&mut self) -> Result<(), SendRequestError> { if self.timeout.is_some() { match self.timeout.as_mut().unwrap().poll() { - Ok(Async::Ready(())) => Err(SendRequestError::Timeout), - Ok(Async::NotReady) => Ok(Async::NotReady), + Ok(Async::Ready(())) => return Err(SendRequestError::Timeout), + Ok(Async::NotReady) => (), Err(_) => unreachable!(), } - } else { - Ok(Async::NotReady) } + Ok(()) } #[inline]