Skip to content

Commit

Permalink
libroach: make DumpThreadStacks thread-safe
Browse files Browse the repository at this point in the history
Release note (bug fix): Fixed a bug where multiple concurrent
invocations of `debug zip` could yield cluster instability. This bug
had been present since CockroachDB v20.1.
  • Loading branch information
knz committed Apr 22, 2021
1 parent b2e556d commit f51e13f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions c-deps/libroach/stack_trace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <memory>
#include <string>
#include <vector>
#include <mutex>

namespace {

Expand Down Expand Up @@ -306,6 +307,11 @@ std::string DumpThreadStacksHelper() {
} // namespace

std::string DumpThreadStacks() {
// This code is not thread-safe: ensure we have only one concurrent call to
// DumpThreadStacks ongoing at a time.
static std::mutex s_mutex;
std::lock_guard<std::mutex> lock(s_mutex);

struct sigaction action;
struct sigaction oldaction;
memset(&action, 0, sizeof(action));
Expand Down

0 comments on commit f51e13f

Please sign in to comment.