aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-11-04 14:27:28 +0100
committerEelco Dolstra <edolstra@gmail.com>2019-11-06 00:55:03 +0100
commit69326f3637f1560407711838e7298d736274ffd4 (patch)
tree636a610a87d82b38085568aec8aa6b33296bf266
parentc119ab9db0edf65379593883c5ed5253549ebbd0 (diff)
Recursive Nix: Handle concurrent client connections
-rw-r--r--src/libstore/build.cc31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index e77512ca4..63557b560 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -895,6 +895,9 @@ private:
/* The daemon main thread. */
std::thread daemonThread;
+ /* The daemon worker threads. */
+ std::vector<std::thread> daemonWorkerThreads;
+
/* Paths that were added via recursive Nix calls. */
PathSet addedPaths;
@@ -2875,17 +2878,19 @@ void DerivationGoal::startDaemon()
debug("received daemon connection");
- // FIXME: process on a separate thread.
- FdSource from(remote.get());
- FdSink to(remote.get());
- try {
- daemon::processConnection(store, from, to,
- daemon::NotTrusted, daemon::Recursive, "nobody", 65535);
- } catch (SysError &) {
- ignoreException();
- }
+ auto workerThread = std::thread([this, store, remote{std::move(remote)}]() {
+ FdSource from(remote.get());
+ FdSink to(remote.get());
+ try {
+ daemon::processConnection(store, from, to,
+ daemon::NotTrusted, daemon::Recursive, "nobody", 65535);
+ debug("terminated daemon connection");
+ } catch (SysError &) {
+ ignoreException();
+ }
+ });
- debug("terminated daemon connection");
+ daemonWorkerThreads.push_back(std::move(workerThread));
}
debug("daemon shutting down");
@@ -2901,6 +2906,12 @@ void DerivationGoal::stopDaemon()
if (daemonThread.joinable())
daemonThread.join();
+ // FIXME: should prune worker threads more quickly.
+ // FIXME: shutdown the client socket to speed up worker termination.
+ for (auto & thread : daemonWorkerThreads)
+ thread.join();
+ daemonWorkerThreads.clear();
+
daemonSocket = -1;
}