diff --git a/include/ylt/coro_rpc/impl/coro_rpc_client.hpp b/include/ylt/coro_rpc/impl/coro_rpc_client.hpp index cc2fa890d..93b6cdf66 100644 --- a/include/ylt/coro_rpc/impl/coro_rpc_client.hpp +++ b/include/ylt/coro_rpc/impl/coro_rpc_client.hpp @@ -722,7 +722,7 @@ class coro_rpc_client { if (!control->has_closed_.compare_exchange_strong(expected, true)) { return; } - control->executor_.schedule([control = std::move(control)]() { + control->executor_.schedule([control]() { asio::error_code ignored_ec; control->socket_.shutdown(asio::ip::tcp::socket::shutdown_both, ignored_ec); @@ -809,7 +809,14 @@ class coro_rpc_client { break; } uint32_t body_len = header.length; - struct_pack::detail::resize(controller->resp_buffer_.read_buf_, body_len); + struct_pack::detail::resize( + controller->resp_buffer_.read_buf_, + std::max(body_len, sizeof(std::string))); + if (body_len < sizeof(std::string)) { /* this strange code just disable + any SSO optimize so that rpc result + wont point to illegal address*/ + controller->resp_buffer_.read_buf_.resize(body_len); + } if (header.attach_length == 0) { ret = co_await coro_io::async_read( socket, diff --git a/src/coro_rpc/examples/base_examples/client.cpp b/src/coro_rpc/examples/base_examples/client.cpp index bc6ca3057..c31ee2949 100644 --- a/src/coro_rpc/examples/base_examples/client.cpp +++ b/src/coro_rpc/examples/base_examples/client.cpp @@ -67,12 +67,16 @@ Lazy show_rpc_call() { // assert(ret.error().code.val() == 404); - ret = co_await client.call(); - assert(ret.value() == "1"); - ret = co_await client.call(); - assert(ret.value() == "2"); - ret = co_await client.call(); - assert(ret.value() == "3"); + auto ret2 = co_await client.call(); + auto str = ret2.value(); + std::cout << ret2.value() << std::endl; + assert(ret2.value() == "1"); + ret2 = co_await client.call(); + std::cout << ret2.value() << std::endl; + assert(ret2.value() == "2"); + ret2 = co_await client.call(); + std::cout << ret2.value() << std::endl; + assert(ret2.value() == "3"); } int main() {