Skip to content

Commit

Permalink
Merge bitcoin#14993: rpc: Fix data race (UB) in InterruptRPC()
Browse files Browse the repository at this point in the history
6c10037 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
  • Loading branch information
laanwj authored and panleone committed Mar 27, 2024
1 parent cf6cb29 commit cb65d0a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/rpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <memory> // for unique_ptr
#include <unordered_map>

static bool fRPCRunning = false;
static std::atomic<bool> g_rpc_running{false};
static bool fRPCInWarmup = true;
static std::string rpcWarmupStatus("RPC server started");
static RecursiveMutex cs_rpcWarmup;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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()
Expand All @@ -350,7 +350,7 @@ void StopRPC()

bool IsRPCRunning()
{
return fRPCRunning;
return g_rpc_running;
}

void SetRPCWarmupStatus(const std::string& newStatus)
Expand Down

0 comments on commit cb65d0a

Please sign in to comment.