Hi, this is my very first issue on Github (yeah, really), so I'm sorry in advance if I'll do something wrong here.
use std::net::SocketAddr;
use hyper::{Request, Response, Body, Error, Server};
use hyper::service::{service_fn, make_service_fn};
async fn handle(
_req: Request<Body>,
_routes: evmap::ReadHandle<&str, &str>
) -> Result<Response<Body>, Error> {
Ok(Response::new(Body::from("Hello world")))
}
#[tokio::main]
async fn main() {
let (map_reader, mut map_writer) = evmap::new();
map_writer.insert("test", "value");
map_writer.refresh();
let svc = make_service_fn(move |_| {
let data = map_reader.clone();
async {
Ok::<_, Error>(service_fn(move |req| {
handle(req, data.clone())
}))
}
});
let addr: SocketAddr = "127.0.0.1:3000".parse().unwrap();
let server = Server::bind(&addr).serve(svc);
if let Err(err) = server.await {
println!("server error: {}", err);
}
}
This code does compile.
Here's the list of dependencies for this example, fairly straightforward:
However, the application consumes ever-growing amount of memory, and it becomes specifically obvious under load testing. It doesn't matter whether _routes
is actually used in the handler. After the handler was executed multiple times, if we print the ReadHandle afterwards, we would see something like this:
ReadHandle {
epochs: Mutex {
data: [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
],
},
epoch: 0,
my_epoch: 0,
}