Skip to content

Commit 1e2b2fc

Browse files
authored
Stop DqGateway in destructor (#17006)
1 parent 2242f96 commit 1e2b2fc

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

ydb/library/yql/providers/dq/provider/yql_dq_gateway.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ class TDqGatewayImpl: public std::enable_shared_from_this<TDqGatewayImpl> {
558558
, Service(GrpcClient.CreateGRpcServiceConnection<Yql::DqsProto::DqService>(GrpcConf))
559559
, TaskScheduler()
560560
, OpenSessionTimeout(timeout)
561+
, IsStopped(false)
561562
{
562563
TaskScheduler.Start();
563564
}
@@ -567,6 +568,11 @@ class TDqGatewayImpl: public std::enable_shared_from_this<TDqGatewayImpl> {
567568
}
568569

569570
void Stop() {
571+
bool expected = false;
572+
if (!IsStopped.compare_exchange_strong(expected, true)) {
573+
return;
574+
}
575+
570576
decltype(Sessions) sessions;
571577
with_lock (Mutex) {
572578
sessions = std::move(Sessions);
@@ -729,6 +735,8 @@ class TDqGatewayImpl: public std::enable_shared_from_this<TDqGatewayImpl> {
729735

730736
TMutex Mutex;
731737
THashMap<TString, std::shared_ptr<TDqGatewaySession>> Sessions;
738+
739+
std::atomic<bool> IsStopped;
732740
};
733741

734742
class TDqGateway: public IDqGateway {
@@ -741,6 +749,7 @@ class TDqGateway: public IDqGateway {
741749
}
742750

743751
~TDqGateway() {
752+
Stop();
744753
}
745754

746755
void Stop() override {

0 commit comments

Comments
 (0)