From cb65d0af5492d917d394e0aab70668764a35dd3d Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 19 Dec 2018 16:02:26 +0100 Subject: [PATCH] Merge #14993: rpc: Fix data race (UB) in InterruptRPC() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6c10037f72073eecc674c313580ef50a4f1e1e44 rpc: Fix data race (UB) in InterruptRPC() (practicalswift) Pull request description: Fix data race (UB) in `InterruptRPC()`. Before: ``` $ ./configure --with-sanitizers=thread $ make $ test/functional/test_runner.py feature_shutdown.py … SUMMARY: ThreadSanitizer: data race rpc/server.cpp:314 in InterruptRPC() … ALL | ✖ Failed | 2 s (accumulated) ``` After: ``` $ ./configure --with-sanitizers=thread $ make $ test/functional/test_runner.py feature_shutdown.py … ALL | ✓ Passed | 3 s (accumulated) ``` Tree-SHA512: b139ca1a0480258f8caa7730cabd7783a821d906630f51487750a6b15b7842675ed679747e1ff1bdade77d248807e9d77bae7bb88da54d1df84a179cd9b9b987 --- src/rpc/server.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 56b10e25b3ac4..133f578548904 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -28,7 +28,7 @@ #include // for unique_ptr #include -static bool fRPCRunning = false; +static std::atomic g_rpc_running{false}; static bool fRPCInWarmup = true; static std::string rpcWarmupStatus("RPC server started"); static RecursiveMutex cs_rpcWarmup; @@ -328,7 +328,7 @@ bool CRPCTable::appendCommand(const std::string& name, const CRPCCommand* pcmd) bool StartRPC() { LogPrint(BCLog::RPC, "Starting RPC\n"); - fRPCRunning = true; + g_rpc_running = true; g_rpcSignals.Started(); return true; } @@ -337,7 +337,7 @@ void InterruptRPC() { LogPrint(BCLog::RPC, "Interrupting RPC\n"); // Interrupt e.g. running longpolls - fRPCRunning = false; + g_rpc_running = false; } void StopRPC() @@ -350,7 +350,7 @@ void StopRPC() bool IsRPCRunning() { - return fRPCRunning; + return g_rpc_running; } void SetRPCWarmupStatus(const std::string& newStatus)