diff options
author | Gleb Vishnevsky <vishnevskiygl@yandex-team.ru> | 2024-08-08 09:29:06 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-08-08 09:38:24 +0300 |
commit | ee2193bf1c142170f0fcd38de910ffc3675e0450 (patch) | |
tree | d92b93fcc8bda5d40e629f4c58a0ac3d6a5e590a | |
parent | c14167c56fc45f2552874f33933ff72f37ca128b (diff) | |
download | ydb-ee2193bf1c142170f0fcd38de910ffc3675e0450.tar.gz |
Add connect timeout
https://github.com/ytsaurus/ytsaurus/issues/641
---
892a9b99acda46357de2fb28cd7160760648b668
Pull Request resolved: https://github.com/ytsaurus/ytsaurus/pull/640
-rw-r--r-- | yt/yt/core/net/config.cpp | 2 | ||||
-rw-r--r-- | yt/yt/core/net/config.h | 1 | ||||
-rw-r--r-- | yt/yt/core/net/dialer.cpp | 36 |
3 files changed, 28 insertions, 11 deletions
diff --git a/yt/yt/core/net/config.cpp b/yt/yt/core/net/config.cpp index 0771c9807f..b6ade7d355 100644 --- a/yt/yt/core/net/config.cpp +++ b/yt/yt/core/net/config.cpp @@ -17,6 +17,8 @@ void TDialerConfig::Register(TRegistrar registrar) registrar.Parameter("rto_scale", &TThis::RtoScale) .GreaterThan(0.0) .Default(2.0); + registrar.Parameter("connect_timeout", &TThis::ConnectTimeout) + .Default(TDuration::Seconds(15)); registrar.Postprocessor([] (TThis* config) { if (config->MaxRto < config->MinRto) { diff --git a/yt/yt/core/net/config.h b/yt/yt/core/net/config.h index 8424b1e928..413748d35c 100644 --- a/yt/yt/core/net/config.h +++ b/yt/yt/core/net/config.h @@ -22,6 +22,7 @@ public: TDuration MinRto; TDuration MaxRto; double RtoScale; + TDuration ConnectTimeout; REGISTER_YSON_STRUCT(TDialerConfig); diff --git a/yt/yt/core/net/dialer.cpp b/yt/yt/core/net/dialer.cpp index 4f1fb9988f..d21b9b0140 100644 --- a/yt/yt/core/net/dialer.cpp +++ b/yt/yt/core/net/dialer.cpp @@ -134,7 +134,7 @@ public: , OnFinished_(std::move(onFinished)) , Id_(TGuid::Create()) , Logger(logger.WithTag("AsyncDialerSession: %v", Id_)) - , Timeout_(Config_->MinRto * GetRandomVariation()) + , ReconnectTimeout_(Config_->MinRto * GetRandomVariation()) { } ~TAsyncDialerSession() @@ -151,6 +151,7 @@ public: YT_VERIFY(!Dialed_); Dialed_ = true; + Deadline_ = Config_->ConnectTimeout.ToDeadLine(); Connect(guard); } @@ -203,7 +204,8 @@ private: SOCKET Socket_ = INVALID_SOCKET; bool Dialed_ = false; bool Finished_ = false; - TDuration Timeout_; + TDuration ReconnectTimeout_; + TInstant Deadline_; TDelayedExecutorCookie TimeoutCookie_; TPollablePtr Pollable_; @@ -287,11 +289,13 @@ private: return; } - if (Config_->EnableAggressiveReconnect) { - TimeoutCookie_ = TDelayedExecutor::Submit( - BIND(&TAsyncDialerSession::OnTimeout, MakeWeak(this)), - Timeout_); - } + auto deadline = Min( + Deadline_, + Config_->EnableAggressiveReconnect ? ReconnectTimeout_.ToDeadLine() : TInstant::Max()); + + TimeoutCookie_ = TDelayedExecutor::Submit( + BIND(&TAsyncDialerSession::OnTimeout, MakeWeak(this)), + deadline); } void OnConnected(TPollable* pollable) @@ -355,12 +359,22 @@ private: CloseSocket(); - if (Timeout_ < Config_->MaxRto) { - Timeout_ *= Config_->RtoScale * GetRandomVariation(); + if (ReconnectTimeout_ < Config_->MaxRto) { + ReconnectTimeout_ *= Config_->RtoScale * GetRandomVariation(); + } + + if (TInstant::Now() >= Deadline_) { + auto error = TError(NRpc::EErrorCode::TransportError, "Connect timeout") + << TErrorAttribute("timeout", Config_->ConnectTimeout); + YT_LOG_ERROR(error); + Finished_ = true; + guard.Release(); + OnFinished_(error); + return; } - YT_LOG_DEBUG("Connect timeout; trying to reconnect (Timeout: %v)", - Timeout_); + YT_LOG_DEBUG("Connect timeout; trying to reconnect (ReconnectTimeout: %v)", + ReconnectTimeout_); Connect(guard); } |