Skip to content

Commit f4c79be

Browse files
authored
Fix memory leak due to a misuse of AWS SDK (#9810)
1 parent 82ee538 commit f4c79be

File tree

26 files changed

+751
-373
lines changed

26 files changed

+751
-373
lines changed

ydb/core/driver_lib/run/kikimr_services_initializers.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,29 @@
243243

244244
#include <util/system/hostname.h>
245245

246+
#ifndef KIKIMR_DISABLE_S3_OPS
247+
#include <aws/core/Aws.h>
248+
#endif
249+
250+
namespace {
251+
252+
#ifndef KIKIMR_DISABLE_S3_OPS
253+
struct TAwsApiGuard {
254+
TAwsApiGuard() {
255+
Aws::InitAPI(Options);
256+
}
257+
258+
~TAwsApiGuard() {
259+
Aws::ShutdownAPI(Options);
260+
}
261+
262+
private:
263+
Aws::SDKOptions Options;
264+
};
265+
#endif
266+
267+
}
268+
246269
namespace NKikimr {
247270

248271
namespace NKikimrServicesInitializers {
@@ -2816,5 +2839,18 @@ void TGraphServiceInitializer::InitializeServices(NActors::TActorSystemSetup* se
28162839
TActorSetupCmd(NGraph::CreateGraphService(appData->TenantName), TMailboxType::HTSwap, appData->UserPoolId));
28172840
}
28182841

2842+
#ifndef KIKIMR_DISABLE_S3_OPS
2843+
TAwsApiInitializer::TAwsApiInitializer(IGlobalObjectStorage& globalObjects)
2844+
: GlobalObjects(globalObjects)
2845+
{
2846+
}
2847+
2848+
void TAwsApiInitializer::InitializeServices(NActors::TActorSystemSetup* setup, const NKikimr::TAppData* appData) {
2849+
Y_UNUSED(setup);
2850+
Y_UNUSED(appData);
2851+
GlobalObjects.AddGlobalObject(std::make_shared<TAwsApiGuard>());
2852+
}
2853+
#endif
2854+
28192855
} // namespace NKikimrServicesInitializers
28202856
} // namespace NKikimr

ydb/core/driver_lib/run/kikimr_services_initializers.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,5 +618,16 @@ class TGraphServiceInitializer : public IKikimrServicesInitializer {
618618
void InitializeServices(NActors::TActorSystemSetup* setup, const NKikimr::TAppData* appData) override;
619619
};
620620

621+
#ifndef KIKIMR_DISABLE_S3_OPS
622+
class TAwsApiInitializer : public IServiceInitializer {
623+
IGlobalObjectStorage& GlobalObjects;
624+
625+
public:
626+
TAwsApiInitializer(IGlobalObjectStorage& globalObjects);
627+
628+
void InitializeServices(NActors::TActorSystemSetup* setup, const NKikimr::TAppData* appData) override;
629+
};
630+
#endif
631+
621632
} // namespace NKikimrServicesInitializers
622633
} // namespace NKikimr

ydb/core/driver_lib/run/run.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,12 @@ TIntrusivePtr<TServiceInitializersList> TKikimrRunner::CreateServiceInitializers
16551655
sil->AddServiceInitializer(new TGraphServiceInitializer(runConfig));
16561656
}
16571657

1658+
#ifndef KIKIMR_DISABLE_S3_OPS
1659+
if (serviceMask.EnableAwsService) {
1660+
sil->AddServiceInitializer(new TAwsApiInitializer(*this));
1661+
}
1662+
#endif
1663+
16581664
return sil;
16591665
}
16601666

ydb/core/driver_lib/run/service_mask.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ union TBasicKikimrServicesMask {
7979
bool EnableGraphService:1;
8080
bool EnableCompDiskLimiter:1;
8181
bool EnableGroupedMemoryLimiter:1;
82+
bool EnableAwsService:1;
8283
};
8384

8485
struct {

ydb/core/driver_lib/run/ya.make

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
LIBRARY(run)
22

3+
IF (OS_WINDOWS)
4+
CFLAGS(
5+
-DKIKIMR_DISABLE_S3_OPS
6+
)
7+
ELSE()
8+
PEERDIR(
9+
contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core
10+
)
11+
ENDIF()
12+
313
SRCS(
414
auto_config_initializer.cpp
515
config.cpp

ydb/core/tx/columnshard/ut_schema/ut_columnshard_schema.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
#include <util/system/hostname.h>
1919
#include <library/cpp/deprecated/atomic/atomic.h>
20+
#include <library/cpp/testing/hook/hook.h>
21+
22+
#include <aws/core/Aws.h>
2023

2124
namespace NKikimr {
2225

@@ -32,6 +35,16 @@ enum class EInitialEviction {
3235

3336
namespace {
3437

38+
Aws::SDKOptions Options;
39+
40+
Y_TEST_HOOK_BEFORE_RUN(InitAwsAPI) {
41+
Aws::InitAPI(Options);
42+
}
43+
44+
Y_TEST_HOOK_AFTER_RUN(ShutdownAwsAPI) {
45+
Aws::ShutdownAPI(Options);
46+
}
47+
3548
static const std::vector<NArrow::NTest::TTestColumn> testYdbSchema = TTestSchema::YdbSchema();
3649
static const std::vector<NArrow::NTest::TTestColumn> testYdbPk = TTestSchema::YdbPkSchema();
3750

ydb/core/tx/columnshard/ut_schema/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ PEERDIR(
1818
library/cpp/getopt
1919
library/cpp/regex/pcre
2020
library/cpp/svnversion
21+
contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core
2122
ydb/core/testlib/default
2223
ydb/core/tx/columnshard/hooks/abstract
2324
ydb/core/tx/columnshard/hooks/testing

ydb/core/tx/datashard/import_s3.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <ydb/core/tablet/resource_broker.h>
1515
#include <ydb/core/wrappers/s3_wrapper.h>
1616
#include <ydb/core/wrappers/s3_storage.h>
17+
#include <ydb/core/wrappers/s3_storage_config.h>
1718
#include <ydb/core/io_formats/ydb_dump/csv_ydb_dump.h>
1819
#include <ydb/public/lib/scheme_types/scheme_type_id.h>
1920

ydb/core/tx/schemeshard/ut_backup/ut_backup.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,27 @@
77
#include <util/string/cast.h>
88
#include <util/string/printf.h>
99

10+
#include <library/cpp/testing/hook/hook.h>
11+
12+
#include <aws/core/Aws.h>
13+
1014
using namespace NSchemeShardUT_Private;
1115
using namespace NKikimr::NWrappers::NTestHelpers;
1216

17+
namespace {
18+
19+
Aws::SDKOptions Options;
20+
21+
Y_TEST_HOOK_BEFORE_RUN(InitAwsAPI) {
22+
Aws::InitAPI(Options);
23+
}
24+
25+
Y_TEST_HOOK_AFTER_RUN(ShutdownAwsAPI) {
26+
Aws::ShutdownAPI(Options);
27+
}
28+
29+
}
30+
1331
Y_UNIT_TEST_SUITE(TBackupTests) {
1432
using TFillFn = std::function<void(TTestBasicRuntime&)>;
1533

ydb/core/tx/schemeshard/ut_backup/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ IF (NOT OS_WINDOWS)
2020
library/cpp/getopt
2121
library/cpp/regex/pcre
2222
library/cpp/svnversion
23+
contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core
2324
ydb/core/testlib/default
2425
ydb/core/tx
2526
ydb/core/tx/schemeshard/ut_helpers

0 commit comments

Comments
 (0)