From f2a42a7a95e39922d5cf65bc826d7c1ed0dc17ab Mon Sep 17 00:00:00 2001 From: zhangyi1357 <34409786+zhangyi1357@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:36:20 +0800 Subject: [PATCH] fix: correct service address handling in grpc plugin (#149) * fix: correct service address handling in grpc plugin - Fixed an issue in the grpc plugin where the service address was incorrectly set during communication with native grpc. This change ensures that the service address is now correctly formatted, improving the reliability of grpc interactions. - Updated the release notes for version 0.10.0 to reflect this fix. * refactor: improve subprocess command formatting in ExampleRunner --- document/sphinx-cn/release_notes/v0_10_0.md | 1 + src/examples/utils/run_all_example.py | 10 ++++++---- src/plugins/grpc_plugin/grpc_rpc_backend.cc | 8 ++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/document/sphinx-cn/release_notes/v0_10_0.md b/document/sphinx-cn/release_notes/v0_10_0.md index 50bac3e54..ee28d5131 100644 --- a/document/sphinx-cn/release_notes/v0_10_0.md +++ b/document/sphinx-cn/release_notes/v0_10_0.md @@ -7,3 +7,4 @@ **次要修改**: +- 修复 grpc 插件与原生 grpc 通信时,服务地址设置不正确的问题 diff --git a/src/examples/utils/run_all_example.py b/src/examples/utils/run_all_example.py index ff106ef74..448c927b5 100644 --- a/src/examples/utils/run_all_example.py +++ b/src/examples/utils/run_all_example.py @@ -37,10 +37,12 @@ class ExampleRunner: with open(version_file, "r") as f: version = f.read().strip() - subprocess.run( - ["pip3", "install", f"./aimrt_py_pkg/dist/aimrt_py-{version}-cp310-cp310-linux_x86_64.whl", "--force-reinstall"], - cwd=default_build_path, - ) + subprocess.run(["pip3", + "install", + f"./aimrt_py_pkg/dist/aimrt_py-{version}-cp310-cp310-linux_x86_64.whl", + "--force-reinstall"], + cwd=default_build_path, + ) subprocess.run( ["bash", os.path.join("build_examples_py_pb_rpc.sh")], cwd=os.path.join(py_cwd, "pb_rpc"), diff --git a/src/plugins/grpc_plugin/grpc_rpc_backend.cc b/src/plugins/grpc_plugin/grpc_rpc_backend.cc index 961da6ee4..8cf39fb08 100644 --- a/src/plugins/grpc_plugin/grpc_rpc_backend.cc +++ b/src/plugins/grpc_plugin/grpc_rpc_backend.cc @@ -163,9 +163,9 @@ bool GrpcRpcBackend::RegisterServiceFunc( return false; } - // pb:/aimrt.protocols.example.ExampleService/GetBarData -> /rpc/aimrt.protocols.example.ExampleService/GetBarData - // ros2:/example_ros2/srv/RosTestRpc -> /rpc/example_ros2/srv/RosTestRpc - auto pattern = "/rpc" + std::string(GetRealFuncName(func_name)); + // pb:/aimrt.protocols.example.ExampleService/GetBarData -> /aimrt.protocols.example.ExampleService/GetBarData + // ros2:/example_ros2/srv/RosTestRpc -> /example_ros2/srv/RosTestRpc + auto pattern = std::string(GetRealFuncName(func_name)); plugins::grpc_plugin::server::HttpHandle http_handle = [this, &service_func_wrapper]( @@ -369,7 +369,7 @@ void GrpcRpcBackend::Invoke( return; } if (url->path.empty()) { - url->path = "/rpc" + std::string(GetRealFuncName(info.func_name)); + url->path = std::string(GetRealFuncName(info.func_name)); } AIMRT_TRACE("Http2 cli session send request, remote addr {}, path: {}", url->host, url->path);