diff options
author | coteeq <coteeq@yandex-team.com> | 2024-08-19 08:12:37 +0300 |
---|---|---|
committer | coteeq <coteeq@yandex-team.com> | 2024-08-19 08:24:04 +0300 |
commit | 775af717c30bba818ca2bc47adae5ae199fcda03 (patch) | |
tree | 4fdcdd70cf807d46c0fed8b691897460a0384fda | |
parent | 4cc6bfa63daf2d82205a9fc20112a11e39fccf91 (diff) | |
download | ydb-775af717c30bba818ca2bc47adae5ae199fcda03.tar.gz |
YT-22582: Break ref cycle in throttle requests
135589354d7ed8fc9f058ca7a64c121527eb9b85
-rw-r--r-- | yt/yt/core/concurrency/throughput_throttler.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/yt/yt/core/concurrency/throughput_throttler.cpp b/yt/yt/core/concurrency/throughput_throttler.cpp index 15320a5915..2d44b355f0 100644 --- a/yt/yt/core/concurrency/throughput_throttler.cpp +++ b/yt/yt/core/concurrency/throughput_throttler.cpp @@ -316,7 +316,7 @@ private: amount, request->TraceContext->GetTraceId()); - promise.OnCanceled(BIND([weakRequest = MakeWeak(request), amount, this, this_ = MakeStrong(this)] (const TError& error) { + promise.OnCanceled(BIND([weakRequest = MakeWeak(request), amount, this, weakThis = MakeWeak(this)] (const TError& error) { auto request = weakRequest.Lock(); if (request && !request->Set.test_and_set()) { NTracing::TTraceContextFinishGuard guard(std::move(request->TraceContext)); @@ -325,8 +325,12 @@ private: amount); request->Promise.Set(TError(NYT::EErrorCode::Canceled, "Throttled request canceled") << error); - QueueTotalAmount_ -= amount; - QueueSizeGauge_.Update(QueueTotalAmount_); + + // NB(coteeq): Weak ref will break cycle "promise -> this -> request -> promise" + if (auto this_ = weakThis.Lock()) { + QueueTotalAmount_ -= amount; + QueueSizeGauge_.Update(QueueTotalAmount_); + } } })); request->Promise = std::move(promise); |