aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshakurov <shakurov@yandex-team.com>2024-08-07 11:36:58 +0300
committershakurov <shakurov@yandex-team.com>2024-08-07 13:17:36 +0300
commitfea13201b3e0dda1db0a5a833f6e6d52ca0f07e3 (patch)
tree4d49c5c7f679827968c407d7f4fecf7b3c3cf334
parent2137507f9ec8a5b7c48cc521943ffa038262a679 (diff)
downloadydb-fea13201b3e0dda1db0a5a833f6e6d52ca0f07e3.tar.gz
Prevent potential use of moved-from context. Minor optimizations around RPC method handlers.
e19616151587f112b19ea960a9cb1aadb2d3923c
-rw-r--r--yt/yt/core/rpc/service_detail.cpp8
-rw-r--r--yt/yt/core/rpc/service_detail.h8
2 files changed, 8 insertions, 8 deletions
diff --git a/yt/yt/core/rpc/service_detail.cpp b/yt/yt/core/rpc/service_detail.cpp
index 285fd3b8f5..5726abe410 100644
--- a/yt/yt/core/rpc/service_detail.cpp
+++ b/yt/yt/core/rpc/service_detail.cpp
@@ -1515,12 +1515,12 @@ void TRequestQueue::RunRequest(TServiceBase::TServiceContextPtr context)
options.SetHeavy(RuntimeInfo_->Heavy.load(std::memory_order::relaxed));
if (options.Heavy) {
- BIND([this, this_ = MakeStrong(this), context, options] {
- return RuntimeInfo_->Descriptor.HeavyHandler.Run(context, options);
+ BIND([context, options, heavyHandler = RuntimeInfo_->Descriptor.HeavyHandler] {
+ return heavyHandler.Run(context, options);
})
.AsyncVia(TDispatcher::Get()->GetHeavyInvoker())
.Run()
- .Subscribe(BIND(&TServiceBase::TServiceContext::CheckAndRun, std::move(context)));
+ .Subscribe(BIND(&TServiceBase::TServiceContext::CheckAndRun, context));
} else {
context->Run(RuntimeInfo_->Descriptor.LiteHandler);
}
@@ -2409,7 +2409,7 @@ void TServiceBase::DecrementActiveRequestCount()
}
}
-void TServiceBase::InitContext(IServiceContextPtr /*context*/)
+void TServiceBase::InitContext(IServiceContext* /*context*/)
{ }
void TServiceBase::RegisterDiscoverRequest(const TCtxDiscoverPtr& context)
diff --git a/yt/yt/core/rpc/service_detail.h b/yt/yt/core/rpc/service_detail.h
index f731ed8454..6fd62e085f 100644
--- a/yt/yt/core/rpc/service_detail.h
+++ b/yt/yt/core/rpc/service_detail.h
@@ -411,7 +411,7 @@ protected:
if (!typedContext->DeserializeRequest()) { \
return; \
} \
- InitContext(typedContext); \
+ InitContext(typedContext.Get()); \
auto* request = &typedContext->Request(); \
auto* response = &typedContext->Response(); \
this->method(request, response, typedContext); \
@@ -426,11 +426,11 @@ protected:
return ::NYT::NRpc::TServiceBase::TLiteHandler(); \
} \
return \
- BIND([=, this] ( \
+ BIND([this, typedContext = std::move(typedContext)] ( \
const ::NYT::NRpc::IServiceContextPtr&, \
const ::NYT::NRpc::THandlerInvocationOptions&) \
{ \
- InitContext(typedContext); \
+ InitContext(typedContext.Get()); \
auto* request = &typedContext->Request(); \
auto* response = &typedContext->Response(); \
this->method(request, response, typedContext); \
@@ -550,7 +550,7 @@ protected:
//! By default, this method does nothing. You may hide this method by a custom implementation
//! (possibly switching argument type to a proper typed context class) in order to customize
//! specific service context before invoking method handler.
- void InitContext(IServiceContextPtr context);
+ void InitContext(IServiceContext* context);
//! Information needed to a register a service method.
struct TMethodDescriptor