Unix jsonrpc server paniced when handling connection
I tried to build a jsonrpc server using unix socket. But it seems like the server throw panic on handling connection.
This is my server code:
fn start_run() {
use karyon_core::async_util::sleep;
use karyon_jsonrpc::Server;
use rpc::Calc;
use std::sync::Arc;
use std::time::Duration;
smol::block_on(async {
let calc = Arc::new(Calc {});
// Creates a new server
let server = Server::builder("unix:///tmp/karyon-test.sock")
.expect("Create a new server builder")
.service(calc.clone())
.pubsub_service(calc)
.build()
.await
.expect("Build a new server");
// Start the server
server.start();
sleep(Duration::MAX).await;
});
}
I use nc -U /tmp/karyon-test.sock to test the server. Below is the server log:
2024-07-04T09:17:01Z INFO karyon_jsonrpc::server] RPC server listens to the endpoint: unix://tmp/karyon-test.sock
thread 'smol-executor' panicked at 'get peer endpoint: IO(Kind(AddrNotAvailable))', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/karyon_jsonrpc-0.1.5/src/server/mod.rs:110:45
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Hello @weiyuhang2011, I just patched a fix for this issue. You can use the karyon_jsonrpc from the master branch until I deploy the new changes and fixes to crates.io.
Thanks for your quick response. But I dont't understand why it can't connect to the server. I think I used the correct socket address.
Hey @weiyuhang2011, yes, the address is correct. You can also just use the path: Server::builder("unix:/tmp/karyon-test.sock"). However, the issue was due to a bug in handling new connections from the server side. It was trying to resolve the client address for debugging.
You can check the patch here: https://github.com/karyontech/karyon/commit/6c65232d741229635151671708556b9af7ef75ac