diff options
author | babenko <babenko@yandex-team.com> | 2023-12-17 11:44:52 +0300 |
---|---|---|
committer | babenko <babenko@yandex-team.com> | 2023-12-17 12:14:14 +0300 |
commit | f8ec1503153a63a648925927b21ffd26c963bd82 (patch) | |
tree | 4f5ac91a647b83c7d35713533fa7211c8564ed7d | |
parent | 85fcbbd6d8436b62e46d5a4e2ed1a6d72b61dc62 (diff) | |
download | ydb-f8ec1503153a63a648925927b21ffd26c963bd82.tar.gz |
Fix crash caused by StdNormalRandom producing a value out of expected range
-rw-r--r-- | yt/yt/core/misc/backoff_strategy.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/yt/yt/core/misc/backoff_strategy.cpp b/yt/yt/core/misc/backoff_strategy.cpp index 4b9e587133..78935a8cbb 100644 --- a/yt/yt/core/misc/backoff_strategy.cpp +++ b/yt/yt/core/misc/backoff_strategy.cpp @@ -59,15 +59,13 @@ TDuration TBackoffStrategy::GetBackoff() const void TBackoffStrategy::ApplyJitter() { - BackoffWithJitter_ = ::NYT::ApplyJitter(Backoff_, Options_.BackoffJitter, +[]{ - //! StdNormalRandom produces [-6.660, 6.660] according to Wiki - const double StdNormalRandomMaxValue = 7.0; - - return StdNormalRandom<double>() / StdNormalRandomMaxValue; + BackoffWithJitter_ = ::NYT::ApplyJitter(Backoff_, Options_.BackoffJitter, [] { + // StdNormalRandom is unlikely to produce a value outside of [-Max, Max] range. + constexpr double Max = 7.0; + return std::clamp(StdNormalRandom<double>() / Max, -1.0, +1.0); }); } - void TBackoffStrategy::UpdateOptions(const TExponentialBackoffOptions& newOptions) { Options_ = newOptions; |