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.
This commit is contained in:
Eelco Dolstra 2017-05-02 14:18:46 +02:00
parent 1a68710d4d
commit cd4d2705ec
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
5 changed files with 19 additions and 1 deletions

View file

@ -167,6 +167,7 @@ int main (int argc, char * * argv)
storeParams["ssh-key"] = bestMachine->sshKey; storeParams["ssh-key"] = bestMachine->sshKey;
sshStore = openStore(bestMachine->storeUri, storeParams); sshStore = openStore(bestMachine->storeUri, storeParams);
sshStore->connect();
storeUri = bestMachine->storeUri; storeUri = bestMachine->storeUri;
} catch (std::exception & e) { } catch (std::exception & e) {

View file

@ -262,6 +262,11 @@ struct LegacySSHStore : public Store
return readStorePaths<PathSet>(*this, conn->from); return readStorePaths<PathSet>(*this, conn->from);
} }
void connect() override
{
auto conn(connections->get());
}
}; };
static RegisterStoreImplementation regStore([]( static RegisterStoreImplementation regStore([](

View file

@ -100,7 +100,7 @@ ref<RemoteStore::Connection> UDSRemoteStore::openConnection()
throw Error(format("socket path %1% is too long") % socketPath); throw Error(format("socket path %1% is too long") % socketPath);
strcpy(addr.sun_path, socketPath.c_str()); 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); throw SysError(format("cannot connect to daemon at %1%") % socketPath);
conn->from.fd = conn->fd.get(); 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() RemoteStore::Connection::~Connection()
{ {
try { try {

View file

@ -92,6 +92,8 @@ public:
PathSet & willBuild, PathSet & willSubstitute, PathSet & unknown, PathSet & willBuild, PathSet & willSubstitute, PathSet & unknown,
unsigned long long & downloadSize, unsigned long long & narSize) override; unsigned long long & downloadSize, unsigned long long & narSize) override;
void connect() override;
protected: protected:
struct Connection struct Connection

View file

@ -582,6 +582,10 @@ public:
state.lock()->pathInfoCache.clear(); 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: protected:
Stats stats; Stats stats;