From a4a287d13620e8eb44eb13393ef98d94f7fe0f5c Mon Sep 17 00:00:00 2001 From: Shou-Li Hsu Date: Thu, 9 Oct 2025 20:27:22 -0700 Subject: [PATCH] Fix pending_requests_ race conditions --- src/endpoint/endpoint.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/endpoint/endpoint.cpp b/src/endpoint/endpoint.cpp index dfd9ca5..c0fc908 100644 --- a/src/endpoint/endpoint.cpp +++ b/src/endpoint/endpoint.cpp @@ -125,6 +125,10 @@ auto RpcEndpoint::SendMethodCall( pending_requests_[request_id] = pending_request; }); + // FIX: Ensure the request is registered before sending to avoid race + // condition + co_await asio::post(endpoint_strand_, asio::use_awaitable); + auto send_result = co_await transport_->SendMessage(message); if (!send_result) { co_return std::unexpected(send_result.error()); @@ -279,7 +283,7 @@ auto RpcEndpoint::HandleResponse(Response response) } }); - co_await asio::post(co_await asio::this_coro::executor, asio::use_awaitable); + co_await asio::post(endpoint_strand_, asio::use_awaitable); if (!found || !request) { co_return RpcError::UnexpectedFromCode(