fix: enhance error checking for server listen address in gRPC plugin (#123)
* feat: enhance error checking for server listen address in gRPC plugin - Added a new method `CheckListenAddr` to validate the listening address for the server. - Integrated error checking in the server initialization to throw an exception if the address is already in use, improving robustness and error handling. * refactor: remove process termination commands from gRPC plugin start scripts - Eliminated the lines that forcefully kill processes listening on ports 50050 and 50051 in the gRPC plugin start scripts. This change simplifies the startup process and avoids potential issues with abrupt terminations.
This commit is contained in:
parent
0b932d1ed8
commit
2e96cbe0f7
@ -1,5 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
lsof -i :50051 | awk 'NR!=1 {print $2}' | xargs kill -9
|
||||
|
||||
./aimrt_main --cfg_file_path=./cfg/examples_plugins_grpc_plugin_pb_rpc_client_cfg.yaml
|
||||
|
@ -1,5 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
lsof -i :50050 | awk 'NR!=1 {print $2}' | xargs kill -9
|
||||
|
||||
./aimrt_main --cfg_file_path=./cfg/examples_plugins_grpc_plugin_pb_rpc_server_cfg.yaml
|
||||
|
@ -67,6 +67,9 @@ class AsioHttp2Server : public std::enable_shared_from_this<AsioHttp2Server> {
|
||||
|
||||
options_ = ServerOptions::Verify(options);
|
||||
connection_options_ptr_ = std::make_shared<ConnectionOptions>(options_);
|
||||
|
||||
AIMRT_CHECK_ERROR_THROW(CheckListenAddr(options_.ep),
|
||||
"{} is already in use.", aimrt::common::util::SSToString(options_.ep));
|
||||
}
|
||||
|
||||
void Start() {
|
||||
@ -173,6 +176,17 @@ class AsioHttp2Server : public std::enable_shared_from_this<AsioHttp2Server> {
|
||||
connection_ptr_list_.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
static bool CheckListenAddr(const boost::asio::ip::tcp::endpoint& ep) {
|
||||
try {
|
||||
IOCtx io;
|
||||
Tcp::acceptor acceptor(io, ep);
|
||||
return true;
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
enum class State : uint32_t {
|
||||
kPreInit,
|
||||
|
Loading…
x
Reference in New Issue
Block a user