From d7d3a4e7743e12fa8cab23296fe7f41faf1fe1f4 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Wed, 15 Feb 2023 16:43:47 -0500 Subject: [PATCH] fix issue #2138 in rpc client, contention on a null lock happened. fix this by making the sending of pings always done in the logic thread. this is done by wrapping the lambda we made with EventLoop::make_caller() --- llarp/rpc/lokid_rpc_client.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/llarp/rpc/lokid_rpc_client.cpp b/llarp/rpc/lokid_rpc_client.cpp index 1bf6b4feb..6f409f88e 100644 --- a/llarp/rpc/lokid_rpc_client.cpp +++ b/llarp/rpc/lokid_rpc_client.cpp @@ -171,7 +171,12 @@ namespace llarp LokidRpcClient::StartPings() { constexpr auto PingInterval = 30s; - auto makePingRequest = [self = shared_from_this()]() { + + auto router = m_Router.lock(); + if (not router) + return; + + auto makePingRequest = router->loop()->make_caller([self = shared_from_this()]() { // send a ping PubKey pk{}; auto r = self->m_Router.lock(); @@ -208,10 +213,11 @@ namespace llarp // reason (e.g. oxend restarts and loses the subscription); we poll using the last known // hash so that the poll is very cheap (basically empty) if the block hasn't advanced. self->UpdateServiceNodeList(); - }; + }); + // Fire one ping off right away to get things going. makePingRequest(); - m_lokiMQ->add_timer(makePingRequest, PingInterval); + m_lokiMQ->add_timer(std::move(makePingRequest), PingInterval); } void