You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to upgrade a server from version 0.14.20 to version 1.2.0, and I'm running into some issues. The server uses tower middleware, and I'm having problems updating it. I've read the server middleware page of the Hyper docs, but that pattern (creating the middleware stack within the handler loop) doesn't look viable for middlewares which need to maintain state.
I've also tried creating the middlware stack outside of the loop and cloning it on each iteration (example below), but I'm stymied by the fact that tower::limit::RateLimit doesn't implement Clone.
let listener = TcpListener::bind(addr).await?;let svc = tower::ServiceBuilder::new().concurrency_limit(10)// Implements Clone: uses an Arc<Semaphore> internally.rate_limit(5,Duration::from_secs(1))// Does not implement Clone.service_fn(|req:Type| /* do some work that takes a long time */);let svc = hyper_util::service::TowerToHyperService(svc);loop{let stream = listener.accept().await.map(|(stream, _)| TokioIo::new(stream))?;
tokio::spawn({let svc = svc.clone();// Error: Clone is not implementedasync{let _ = hyper::server::conn::http2::Builder::new(TokioExecutor::new()).serve_connection(stream, svc.clone()).await;}});}
What is the recommended path forward here? Is there a way to make tower::limit::RateLimit work with hyper 1.0, or is the recommendation to simply not use it and either switch over to some kind of other rate limiter or write our own rate limiter that is Cloneable?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I'm trying to upgrade a server from version 0.14.20 to version 1.2.0, and I'm running into some issues. The server uses tower middleware, and I'm having problems updating it. I've read the server middleware page of the Hyper docs, but that pattern (creating the middleware stack within the handler loop) doesn't look viable for middlewares which need to maintain state.
I've also tried creating the middlware stack outside of the loop and cloning it on each iteration (example below), but I'm stymied by the fact that
tower::limit::RateLimit
doesn't implementClone
.What is the recommended path forward here? Is there a way to make
tower::limit::RateLimit
work with hyper 1.0, or is the recommendation to simply not use it and either switch over to some kind of other rate limiter or write our own rate limiter that isClone
able?Beta Was this translation helpful? Give feedback.
All reactions