summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/buildstream/_context.py19
-rw-r--r--src/buildstream/_scheduler/scheduler.py4
2 files changed, 10 insertions, 13 deletions
diff --git a/src/buildstream/_context.py b/src/buildstream/_context.py
index 7ff993166..879555089 100644
--- a/src/buildstream/_context.py
+++ b/src/buildstream/_context.py
@@ -526,19 +526,16 @@ class Context():
log_level=log_level)
return self._cascache
- # is_fork_allowed():
+ # prepare_fork():
#
- # Return whether fork without exec is allowed. This is a safeguard against
+ # Prepare this process for fork without exec. This is a safeguard against
# fork issues with multiple threads and gRPC connections.
#
- def is_fork_allowed(self):
- # Do not allow fork if there are background threads.
- if not utils._is_single_threaded():
- return False
-
- # Do not allow fork if there are open gRPC channels.
+ def prepare_fork(self):
+ # gRPC channels must be closed before fork.
for cache in [self._cascache, self._artifactcache, self._sourcecache]:
- if cache and cache.has_open_grpc_channels():
- return False
+ if cache:
+ cache.close_grpc_channels()
- return True
+ # Do not allow fork if there are background threads.
+ return utils._is_single_threaded()
diff --git a/src/buildstream/_scheduler/scheduler.py b/src/buildstream/_scheduler/scheduler.py
index 08db1a1e9..d3faa2a8e 100644
--- a/src/buildstream/_scheduler/scheduler.py
+++ b/src/buildstream/_scheduler/scheduler.py
@@ -406,8 +406,8 @@ class Scheduler():
# If that happens, do another round.
process_queues = any(q.dequeue_ready() for q in self.queues)
- # Check whether fork is allowed before starting jobs
- if not self.context.is_fork_allowed():
+ # Make sure fork is allowed before starting jobs
+ if not self.context.prepare_fork():
message = Message(MessageType.BUG, "Fork is not allowed", detail="Background threads are active")
self._notify(Notification(NotificationType.MESSAGE, message=message))
self.terminate_jobs()