From 5dcf64c128d23862b1e03f50999a7f3e134fc076 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Mon, 7 Sep 2020 13:15:56 -0400 Subject: [PATCH] fix(tvix): Make working flag thread_local Since the daemon is running in threads now rather than forking a process per connection (thanks to grpc) this static flag to prevent accidentally initializing a new worker during a build is getting stepped on by multiple threads. This converts it to thread-local, and also adds an actual message to the check so that if it hits in the future we know what's going on. Fixes: b/58 Change-Id: I07a2f1582e56709c104f79935e5405fa24888f59 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1940 Tested-by: BuildkiteCI Reviewed-by: kanepyork Reviewed-by: V --- third_party/nix/src/libstore/build.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/third_party/nix/src/libstore/build.cc b/third_party/nix/src/libstore/build.cc index 502281d00..a009651c9 100644 --- a/third_party/nix/src/libstore/build.cc +++ b/third_party/nix/src/libstore/build.cc @@ -4241,14 +4241,13 @@ void SubstitutionGoal::handleEOF(int fd) { ////////////////////////////////////////////////////////////////////// -static bool working = false; +ABSL_CONST_INIT static thread_local bool working = false; Worker::Worker(LocalStore& store, std::ostream& log_sink) : log_sink_(log_sink), store(store) { - /* Debugging: prevent recursive workers. */ - if (working) { - abort(); - } + // Debugging: prevent recursive workers. + // TODO(grfn): Do we need this? + CHECK(!working) << "Worker initialized during execution of a worker"; working = true; nrLocalBuilds = 0; lastWokenUp = steady_time_point::min();