about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-05-02T12·18+0200
committerEelco Dolstra <edolstra@gmail.com>2017-05-02T13·46+0200
commitcd4d2705ec6e641ffa3b11dc1aabad22fc38251a (patch)
tree78ea8c0f0f64877588af1c0ee1fe94139e5ecfbd
parent1a68710d4dff609bbaf61db3e17a2573f0aadf17 (diff)
build-remote: Fix fallback to other machines when connecting fails
Opening an SSHStore or LegacySSHStore does not actually establish a
connection, so the try/catch block here did nothing. Added a
Store::connect() method to test whether a connection can be
established.
-rw-r--r--src/build-remote/build-remote.cc1
-rw-r--r--src/libstore/legacy-ssh-store.cc5
-rw-r--r--src/libstore/remote-store.cc8
-rw-r--r--src/libstore/remote-store.hh2
-rw-r--r--src/libstore/store-api.hh4
5 files changed, 19 insertions, 1 deletions
diff --git a/src/build-remote/build-remote.cc b/src/build-remote/build-remote.cc
index 5cd3c518b787..8876da6c063c 100644
--- a/src/build-remote/build-remote.cc
+++ b/src/build-remote/build-remote.cc
@@ -167,6 +167,7 @@ int main (int argc, char * * argv)
                         storeParams["ssh-key"] = bestMachine->sshKey;
 
                     sshStore = openStore(bestMachine->storeUri, storeParams);
+                    sshStore->connect();
                     storeUri = bestMachine->storeUri;
 
                 } catch (std::exception & e) {
diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc
index a6479a450e34..e09932e3d182 100644
--- a/src/libstore/legacy-ssh-store.cc
+++ b/src/libstore/legacy-ssh-store.cc
@@ -262,6 +262,11 @@ struct LegacySSHStore : public Store
 
         return readStorePaths<PathSet>(*this, conn->from);
     }
+
+    void connect() override
+    {
+        auto conn(connections->get());
+    }
 };
 
 static RegisterStoreImplementation regStore([](
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index af59d51106fc..be8819bbc004 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -100,7 +100,7 @@ ref<RemoteStore::Connection> UDSRemoteStore::openConnection()
         throw Error(format("socket path ‘%1%’ is too long") % socketPath);
     strcpy(addr.sun_path, socketPath.c_str());
 
-    if (connect(conn->fd.get(), (struct sockaddr *) &addr, sizeof(addr)) == -1)
+    if (::connect(conn->fd.get(), (struct sockaddr *) &addr, sizeof(addr)) == -1)
         throw SysError(format("cannot connect to daemon at ‘%1%’") % socketPath);
 
     conn->from.fd = conn->fd.get();
@@ -613,6 +613,12 @@ void RemoteStore::queryMissing(const PathSet & targets,
 }
 
 
+void RemoteStore::connect()
+{
+    auto conn(connections->get());
+}
+
+
 RemoteStore::Connection::~Connection()
 {
     try {
diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh
index 479cf3a7909d..ed430e4cabb6 100644
--- a/src/libstore/remote-store.hh
+++ b/src/libstore/remote-store.hh
@@ -92,6 +92,8 @@ public:
         PathSet & willBuild, PathSet & willSubstitute, PathSet & unknown,
         unsigned long long & downloadSize, unsigned long long & narSize) override;
 
+    void connect() override;
+
 protected:
 
     struct Connection
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index 8ca3f4b27d06..b06f5d86a93a 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -582,6 +582,10 @@ public:
         state.lock()->pathInfoCache.clear();
     }
 
+    /* Establish a connection to the store, for store types that have
+       a notion of connection. Otherwise this is a no-op. */
+    virtual void connect() { };
+
 protected:
 
     Stats stats;