From d1158bb8168804b27508972988d4b85ba9d5e49d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 3 Mar 2017 19:35:34 +0100 Subject: [PATCH] Cache connection failures --- src/libstore/remote-store.cc | 15 ++++++++++++++- src/libstore/remote-store.hh | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 5e62bd3d5..1ac2d7b6e 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -44,13 +44,26 @@ RemoteStore::RemoteStore(const Params & params) : Store(params) , connections(make_ref>( std::max(1, std::stoi(get(params, "max-connections", "1"))), - [this]() { return openConnection(); }, + [this]() { return openConnectionWrapper(); }, [](const ref & r) { return r->to.good() && r->from.good(); } )) { } +ref RemoteStore::openConnectionWrapper() +{ + if (failed) + throw Error("opening a connection to remote store ā€˜%sā€™ previously failed", getUri()); + try { + return openConnection(); + } catch (...) { + failed = true; + throw; + } +} + + UDSRemoteStore::UDSRemoteStore(const Params & params) : Store(params) , LocalFSStore(params) diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh index ed7b27c88..66540a2a2 100644 --- a/src/libstore/remote-store.hh +++ b/src/libstore/remote-store.hh @@ -98,6 +98,8 @@ protected: void processStderr(Sink * sink = 0, Source * source = 0); }; + ref openConnectionWrapper(); + virtual ref openConnection() = 0; void initConnection(Connection & conn); @@ -106,6 +108,8 @@ protected: private: + std::atomic_bool failed{false}; + void setOptions(Connection & conn); };