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 <rikingcoding@gmail.com>
Reviewed-by: V <v@anomalous.eu>
This commit is contained in:
Griffin Smith 2020-09-07 13:15:56 -04:00 committed by glittershark
parent 0d1f6d0592
commit 5dcf64c128

View file

@ -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) Worker::Worker(LocalStore& store, std::ostream& log_sink)
: log_sink_(log_sink), store(store) { : log_sink_(log_sink), store(store) {
/* Debugging: prevent recursive workers. */ // Debugging: prevent recursive workers.
if (working) { // TODO(grfn): Do we need this?
abort(); CHECK(!working) << "Worker initialized during execution of a worker";
}
working = true; working = true;
nrLocalBuilds = 0; nrLocalBuilds = 0;
lastWokenUp = steady_time_point::min(); lastWokenUp = steady_time_point::min();