Replies: 2 comments 6 replies
-
@niklasad1 to ask one more Q on this. I've implemented: let runtime_hdl = Handle::current();
let listener_v4 = TcpListener::bind(&self.v4_addr).await?;
let listener_v6 = TcpListener::bind(&self.v6_addr).await?;
let (stop_hdl, server_hdl) = stop_channel();
let svc = jsonrpsee::server::Server::builder()
.custom_tokio_runtime(runtime_hdl.clone())
.set_http_middleware(middleware)
.set_id_provider(Box::new(RandomStringIdProvider::new(16)))
.set_message_buffer_capacity(self.capacity as u32)
.to_service_builder()
.build(module.into_inner(), stop_hdl.clone());
let server_hdl2 = server_hdl.clone();
runtime_hdl.clone().spawn(async move {
loop {
let stream = select! {
result = listener_v4.accept() => {
if let Ok((stream, _remote_addr)) = result {
stream
} else {
continue
}
}
result = listener_v6.accept() => {
if let Ok((stream, _remote_addr)) = result {
stream
} else {
continue
}
}
_ = server_hdl2.clone().stopped() => {
break;
}
};
let svc = svc.clone();
runtime_hdl.spawn(async move {
if let Err(err) = hyper::server::conn::Http::new()
.serve_connection(stream, svc)
.with_upgrades()
.await
{
error!("error while serving HTTP connection: {err}");
}
});
}
});
Ok(server_hdl) While connections to both sockets work, when previously using let _ = ws_hdl.stop();
ws_hdl.stopped().await; But, now this won't work. I attempted returning both the server_handle and stop_handle and calling let _ = ws_hdl.stop();
ws_stop_hdl.shutdown().await; But, this still doesn't seem to control the shutdown correctly. Any ideas here that I'm just missing? There are alternatives like listening on a specified channel for the shutdown, but previously it worked in a built-in way, essentially. Thoughts? Thanks. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Howdy all, akin to https://github.com/tokio-rs/axum/blob/main/examples/listen-multiple-addrs/src/main.rs, would it be possible to have the jsonrpsee server accept connections on either a V6 socket or a V4 socket? I wasn't sure if there were issues with how Hyper/Tokio gets wrapped? Otherwise, would it be possible to do a v4/v6 fallback?
Solution:
Beta Was this translation helpful? Give feedback.
All reactions