diff --git a/cpp/cdc/CDC.cpp b/cpp/cdc/CDC.cpp index 7741855e..2518376f 100644 --- a/cpp/cdc/CDC.cpp +++ b/cpp/cdc/CDC.cpp @@ -493,27 +493,31 @@ public: } void run() { + EggsTime successfulIterationAt = 0; auto shards = std::make_unique>(); for (;;) { + std::this_thread::sleep_for(std::chrono::milliseconds(10)); if (_shared.stop.load()) { return; } + if (successfulIterationAt - eggsNow() < 1_mins) { + continue; + } std::string err = fetchShards(_shuckleHost, _shucklePort, 100_ms, *shards); if (!err.empty()) { - LOG_INFO(_env, "failed to reach shuckle at %s:%s to fetch shards, might retry: %s", _shuckleHost, _shucklePort, err); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + LOG_INFO(_env, "failed to reach shuckle at %s:%s to fetch shards, will retry: %s", _shuckleHost, _shucklePort, err); + EggsTime successfulIterationAt = 0; continue; } bool badShard = false; for (int i = 0; i < shards->size(); i++) { if (shards->at(i).port == 0) { - LOG_DEBUG(_env, "Shard %s not ready yet", i); badShard = true; break; } } if (badShard) { - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + EggsTime successfulIterationAt = 0; continue; } { @@ -523,7 +527,7 @@ public: } } LOG_INFO(_env, "successfully fetched all shards from shuckle, will wait one minute"); - std::this_thread::sleep_for(std::chrono::minutes(1)); + EggsTime successfulIterationAt = eggsNow(); } } }; diff --git a/cpp/core/Shuckle.cpp b/cpp/core/Shuckle.cpp index 21da57ce..3d75f5d5 100644 --- a/cpp/core/Shuckle.cpp +++ b/cpp/core/Shuckle.cpp @@ -46,7 +46,8 @@ static int shuckleSock(const std::string& host, uint16_t port, Duration timeout, throw SYSCALL_EXCEPTION("socket"); } - int synRetries = 1; + // We retry upstream anyway, and we want prompt termination of `connect` + int synRetries = 0; setsockopt(sock, IPPROTO_TCP, TCP_SYNCNT, &synRetries, sizeof(synRetries)); struct sockaddr_in shuckleAddr; diff --git a/cpp/shard/Shard.cpp b/cpp/shard/Shard.cpp index a35d2818..c37f602f 100644 --- a/cpp/shard/Shard.cpp +++ b/cpp/shard/Shard.cpp @@ -272,25 +272,29 @@ public: } void run() { + EggsTime successfulIterationAt = 0; for (;;) { + std::this_thread::sleep_for(std::chrono::milliseconds(10)); if (_shared.stop.load()) { return; } + if (successfulIterationAt - eggsNow() < 1_mins) { + continue; + } uint16_t port = _shared.ownPort.load(); if (port == 0) { // shard server isn't up yet - std::this_thread::sleep_for(std::chrono::milliseconds(10)); continue; } LOG_INFO(_env, "Registering ourselves (shard %s, port %s) with shuckle", _shid, port); std::string err = registerShard(_shuckleHost, _shucklePort, 100_ms, _shid, _ownIp, port); if (!err.empty()) { RAISE_ALERT(_env, "Couldn't register ourselves with shuckle: %s", err); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + EggsTime successfulIterationAt = 0; continue; } LOG_INFO(_env, "Successfully registered with shuckle, will register again in one minute"); - std::this_thread::sleep_for(std::chrono::minutes(1)); + successfulIterationAt = eggsNow(); } } };