Periodically close RemoteStore connections

This prevents an accumulation of temproots. See
89dc62c174.
This commit is contained in:
Eelco Dolstra 2017-09-14 18:16:33 +02:00
parent 6517446c34
commit b828224fee
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -8,6 +8,7 @@
#include "state.hh"
#include "build-result.hh"
#include "store-api.hh"
#include "remote-store.hh"
#include "shared.hh"
#include "globals.hh"
@ -814,6 +815,7 @@ void State::run(BuildID buildOne)
Store::Params localParams;
localParams["max-connections"] = "16";
localParams["max-connection-age"] = "600";
localStore = openStore(getEnv("NIX_REMOTE"), localParams);
auto storeUri = config->getStrOption("store_uri");
@ -891,6 +893,20 @@ void State::run(BuildID buildOne)
}
}).detach();
/* Make sure that old daemon connections are closed even when
we're not doing much. */
std::thread([&]() {
while (true) {
sleep(10);
try {
if (auto remoteStore = getDestStore().dynamic_pointer_cast<RemoteStore>())
remoteStore->flushBadConnections();
} catch (std::exception & e) {
printMsg(lvlError, format("connection flush thread: %1%") % e.what());
}
}
}).detach();
/* Monitor the database for status dump requests (e.g. from
hydra-queue-runner --status). */
while (true) {