From d46c0c6611576cab0ee8d1da0ec930d278de220a Mon Sep 17 00:00:00 2001 From: aiwe Date: Sun, 5 May 2024 17:42:35 -0500 Subject: [PATCH] Fix running wallet rpc and logging in walletd can possibly delete event and dispatcher from JsonRpcServer --- src/JsonRpcServer/JsonRpcServer.cpp | 10 ---------- src/PaymentGateService/PaymentGateService.cpp | 12 +++++++++++- src/Wallet/WalletRpcServer.cpp | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/JsonRpcServer/JsonRpcServer.cpp b/src/JsonRpcServer/JsonRpcServer.cpp index a59c2efd71..687a6199d9 100755 --- a/src/JsonRpcServer/JsonRpcServer.cpp +++ b/src/JsonRpcServer/JsonRpcServer.cpp @@ -60,8 +60,6 @@ void JsonRpcServer::start(const std::string& bindAddress, uint16_t bindPort, uin } m_workers.push_back(std::thread(std::bind(&JsonRpcServer::listen, this, bindAddress, bindPort))); - - stopEvent->wait(); } void JsonRpcServer::stop() { @@ -71,14 +69,6 @@ void JsonRpcServer::stop() { http->stop(); - if (m_dispatcher != nullptr) { - m_dispatcher->remoteSpawn([&]() { - if (stopEvent != nullptr) { - stopEvent->set(); - } - }); - } - for (auto& th : m_workers) { if (th.joinable()) { th.join(); diff --git a/src/PaymentGateService/PaymentGateService.cpp b/src/PaymentGateService/PaymentGateService.cpp index 18c13c2532..a12027e27b 100755 --- a/src/PaymentGateService/PaymentGateService.cpp +++ b/src/PaymentGateService/PaymentGateService.cpp @@ -347,14 +347,24 @@ void PaymentGateService::runWalletService(const CryptoNote::Currency& currency, rpcServer.setAuth(config.gateConfiguration.m_rpcUser, config.gateConfiguration.m_rpcPassword); - Tools::SignalHandler::install([&rpcServer] { + Tools::SignalHandler::install([&] { rpcServer.stop(); + + if (dispatcher != nullptr) { + dispatcher->remoteSpawn([&]() { + if (stopEvent != nullptr) { + stopEvent->set(); + } + }); + } }); rpcServer.start(config.gateConfiguration.m_bind_address, config.gateConfiguration.m_bind_port, config.gateConfiguration.m_bind_port_ssl); + stopEvent->wait(); + Logging::LoggerRef(logger, "PaymentGateService")(Logging::INFO, Logging::BRIGHT_WHITE) << "JSON-RPC server stopped, stopping wallet service..."; try { diff --git a/src/Wallet/WalletRpcServer.cpp b/src/Wallet/WalletRpcServer.cpp index 642643e4fb..0f8fb6359c 100644 --- a/src/Wallet/WalletRpcServer.cpp +++ b/src/Wallet/WalletRpcServer.cpp @@ -91,7 +91,7 @@ wallet_rpc_server::wallet_rpc_server( //------------------------------------------------------------------------------------------------------------------------------ -wallet_rpc_server::~wallet_rpc_server() { +wallet_rpc_server::~wallet_rpc_server() { } //------------------------------------------------------------------------------------------------------------------------------