about summary refs log tree commit diff
path: root/third_party/nix/src/libstore
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2020-09-07T17·15-0400
committerglittershark <grfn@gws.fyi>2020-09-10T17·03+0000
commit5dcf64c128d23862b1e03f50999a7f3e134fc076 (patch)
tree7582da12c858281a083a7b66f469320d5148d7a1 /third_party/nix/src/libstore
parent0d1f6d059258ce01a46830c30de0b5c965995368 (diff)
fix(tvix): Make working flag thread_local r/1782
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 <rikingcoding@gmail.com>
Reviewed-by: V <v@anomalous.eu>
Diffstat (limited to 'third_party/nix/src/libstore')
-rw-r--r--third_party/nix/src/libstore/build.cc9
1 files changed, 4 insertions, 5 deletions
diff --git a/third_party/nix/src/libstore/build.cc b/third_party/nix/src/libstore/build.cc
index 502281d0051c..a009651c9d96 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();