Merge #14993: rpc: Fix data race (UB) in InterruptRPC()

6c10037f72 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
This commit is contained in:
Wladimir J. van der Laan 2018-12-19 16:02:26 +01:00
commit cb52cee29d
No known key found for this signature in database
GPG key ID: 1E4AED62986CD25D
2 changed files with 4 additions and 7 deletions

View file

@ -24,7 +24,7 @@
#include <unordered_map> #include <unordered_map>
static CCriticalSection cs_rpcWarmup; static CCriticalSection cs_rpcWarmup;
static bool fRPCRunning = false; static std::atomic<bool> g_rpc_running{false};
static bool fRPCInWarmup GUARDED_BY(cs_rpcWarmup) = true; static bool fRPCInWarmup GUARDED_BY(cs_rpcWarmup) = true;
static std::string rpcWarmupStatus GUARDED_BY(cs_rpcWarmup) = "RPC server started"; static std::string rpcWarmupStatus GUARDED_BY(cs_rpcWarmup) = "RPC server started";
/* Timer-creating functions */ /* Timer-creating functions */
@ -303,7 +303,7 @@ bool CRPCTable::appendCommand(const std::string& name, const CRPCCommand* pcmd)
void StartRPC() void StartRPC()
{ {
LogPrint(BCLog::RPC, "Starting RPC\n"); LogPrint(BCLog::RPC, "Starting RPC\n");
fRPCRunning = true; g_rpc_running = true;
g_rpcSignals.Started(); g_rpcSignals.Started();
} }
@ -311,7 +311,7 @@ void InterruptRPC()
{ {
LogPrint(BCLog::RPC, "Interrupting RPC\n"); LogPrint(BCLog::RPC, "Interrupting RPC\n");
// Interrupt e.g. running longpolls // Interrupt e.g. running longpolls
fRPCRunning = false; g_rpc_running = false;
} }
void StopRPC() void StopRPC()
@ -324,7 +324,7 @@ void StopRPC()
bool IsRPCRunning() bool IsRPCRunning()
{ {
return fRPCRunning; return g_rpc_running;
} }
void SetRPCWarmupStatus(const std::string& newStatus) void SetRPCWarmupStatus(const std::string& newStatus)

View file

@ -7,9 +7,6 @@ deadlock:WalletBatch
# Intentional deadlock in tests # Intentional deadlock in tests
deadlock:TestPotentialDeadLockDetected deadlock:TestPotentialDeadLockDetected
# fRPCRunning race
race:InterruptRPC
# Wildcard for all gui tests, should be replaced with non-wildcard suppressions # Wildcard for all gui tests, should be replaced with non-wildcard suppressions
race:src/qt/test/* race:src/qt/test/*
deadlock:src/qt/test/* deadlock:src/qt/test/*