Skip to content

Commit

Permalink
sleep before connection
Browse files Browse the repository at this point in the history
  • Loading branch information
danovaro committed Oct 31, 2024
1 parent f8652cb commit 0d61134
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/fdb5/remote/client/ClientConnectionRouter.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "fdb5/remote/client/ClientConnectionRouter.h"

#include <chrono>
#include <random>
#include <thread>

namespace{

class ConnectionError : public eckit::Exception {
Expand Down Expand Up @@ -37,6 +41,17 @@ ClientConnection& ClientConnectionRouter::connection(const eckit::net::Endpoint&
return *(it->second);
} else {
ClientConnection* clientConnection = new ClientConnection{endpoint, defaultEndpoint};

static int fdbConnectMaxSleep = eckit::Resource<int>("fdbConnectMaxSleep", 0);

if (fdbConnectMaxSleep) {
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_int_distribution<int> dist(0, fdbConnectMaxSleep);

std::this_thread::sleep_for(std::chrono::milliseconds(dist(rd)));
}

if (clientConnection->connect()) {
auto it = (connections_.emplace(endpoint, std::unique_ptr<ClientConnection>(clientConnection))).first;
return *(it->second);
Expand Down

0 comments on commit 0d61134

Please sign in to comment.