-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Using tower layers #2132
Comments
Adding the full example to reproduce:
If I move |
There's two steps involved here, and both make use of
By adding the timeout to the If you want to instead put the timeout on handling requests/responses, you could use a impl<T> Service<T> for MakeSvc {
type Response = Svc;
type Error = std::io::Error;
type Future = Pin<Box<dyn Future<Output=Result<Self::Response, Self::Error>> + Send>>;
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { Ok(()).into() }
fn call(&mut self, _: T) -> Self::Future {
Box::pin(async {
// A service to handle the requests of the connection `T`
let svc = ServiceBuilder::new()
.timeout(Duration::from_secs(2))
.service(Svc);
Ok(svc)
})
Box::pin(fut)
}
} Note that hyper doesn't have specific knowledge of the timeout error that will occur, so you may wish to add a layer that converts errors into I'm going to close this as it's more a usage question than a bug in hyper. |
Thank you, that makes sense. and yes, definitely not a bug |
Hi, Rust and Hyper noob here so excuse my ignorance.
I am trying to build on the Tower server example (https://github.com/hyperium/hyper/blob/master/examples/tower_server.rs) by adding a timeout layer but it does not seem to work as expected.
I'm using a
ServiceBuilder
to construct the service:and then passing that to
serve
.The stack seems to be constructed correctly:
and after some debugging I can see that the
call
function inTimeout
does get called but it looks like the response is returned fromMakeSvc
immediately beforecall
gets called inSvc
, effectively bypassing the timeout check.Any ideas on what I could be missing?
The text was updated successfully, but these errors were encountered: