Skip to content

Commit ab80f0c

Browse files
authored
Fix incorrect stopping actorsystem before grpc (#27535)
1 parent b26f64c commit ab80f0c

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

ydb/core/driver_lib/run/run.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,17 @@ namespace NKikimr {
177177

178178
namespace {
179179

180-
void StopGRpcServers(std::weak_ptr<TGRpcServersWrapper> grpcServersWrapper) {
180+
void StopGRpcServers(std::weak_ptr<TGRpcServersWrapper> grpcServersWrapper, bool isDisabled = false) {
181181
auto wrapper = grpcServersWrapper.lock();
182182
if (!wrapper) {
183183
return;
184184
}
185+
if (wrapper->IsDisabled.load(std::memory_order_acquire)) {
186+
return;
187+
}
188+
if (isDisabled) {
189+
wrapper->IsDisabled.store(true, std::memory_order_release);
190+
}
185191
TGuard<TMutex> guard = wrapper->Guard();
186192
for (auto& [name, server] : wrapper->Servers) {
187193
if (!server) {
@@ -191,7 +197,6 @@ namespace {
191197
}
192198
wrapper->Servers.clear();
193199
}
194-
195200
}
196201

197202
class TGRpcServersManager : public TActorBootstrapped<TGRpcServersManager> {
@@ -265,6 +270,9 @@ class TGRpcServersManager : public TActorBootstrapped<TGRpcServersManager> {
265270
if (!wrapper) {
266271
return;
267272
}
273+
if (wrapper->IsDisabled.load(std::memory_order_acquire)) {
274+
return;
275+
}
268276
TGuard<TMutex> guard = wrapper->Guard();
269277
wrapper->Servers = wrapper->GrpcServersFactory();
270278
for (auto& [name, server] : wrapper->Servers) {
@@ -317,6 +325,7 @@ class TGRpcServersManager : public TActorBootstrapped<TGRpcServersManager> {
317325
hFunc(TEvStop, HandleStop)
318326
cFunc(TEvGRpcServersManager::EvDisconnectRequestStarted, HandleDisconnectRequestStarted)
319327
cFunc(TEvGRpcServersManager::EvDisconnectRequestFinished, HandleDisconnectRequestFinished)
328+
cFunc(TEvents::TSystem::PoisonPill, PassAway)
320329
)
321330
};
322331

@@ -2153,14 +2162,13 @@ void TKikimrRunner::KikimrStop(bool graceful) {
21532162
SqsHttp.Destroy();
21542163
}
21552164

2156-
if (ActorSystem) {
2157-
ActorSystem->Stop();
2158-
}
2159-
21602165
// stop processing grpc requests/response - we must stop feeding ActorSystem
21612166
if (GRpcServersManager) {
2162-
StopGRpcServers(GRpcServersWrapper);
2163-
GRpcServersWrapper->Servers.clear();
2167+
StopGRpcServers(GRpcServersWrapper, true);
2168+
}
2169+
2170+
if (ActorSystem) {
2171+
ActorSystem->Stop();
21642172
}
21652173

21662174
if (YqSharedResources) {

ydb/core/driver_lib/run/run.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct TGRpcServersWrapper {
3333
TGRpcServers Servers;
3434
TGRpcServersFactory GrpcServersFactory;
3535
TMutex Mutex;
36+
std::atomic<bool> IsDisabled = false;
3637

3738
TGuard<TMutex> Guard() {
3839
return TGuard<TMutex>(Mutex);

0 commit comments

Comments
 (0)