Skip to content

Commit 188c5f5

Browse files
staugustfacebook-github-bot
authored andcommitted
fix static variable client access vialotion in DamonConfigLoader (#965)
Summary: As discussed in pytorch issue [#129626](pytorch/pytorch#129626) , `updateThread` of `Config` will keep on accessing `client` after main thread quits. But when main thread quits, `client` will be destructed. Functions in `updateThread` may use a dangling pointer of `client`, which will cause invalid memory access, and finally, `Segment fault` occurs, a core file will be generated, which doesn't behave as expected. Pull Request resolved: #965 Reviewed By: xuzhao9 Differential Revision: D60291572 Pulled By: aaronenyeshi fbshipit-source-id: d97291aa825deeb672eb8e2d8385633c2838396d
1 parent c2bc752 commit 188c5f5

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

libkineto/src/DaemonConfigLoader.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
#include "Logger.h"
1414
#include "ConfigLoader.h"
1515
#include "DaemonConfigLoader.h"
16-
#include "IpcFabricConfigClient.h"
1716

1817
namespace KINETO_NAMESPACE {
1918

2019
// TODO : implications of this singleton being thread safe on forks?
21-
IpcFabricConfigClient* getConfigClient() {
22-
static auto client = std::make_unique<IpcFabricConfigClient>();
23-
return client.get();
20+
IpcFabricConfigClient* DaemonConfigLoader::getConfigClient() {
21+
if (!configClient){
22+
configClient = std::make_unique<IpcFabricConfigClient>();
23+
}
24+
return configClient.get();
2425
}
2526

2627
std::string DaemonConfigLoader::readBaseConfig() {

libkineto/src/DaemonConfigLoader.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#if !USE_GOOGLE_LOG
1515
#include <memory>
1616
#endif // !USE_GOOGLE_LOG
17+
#ifdef __linux__
18+
#include "IpcFabricConfigClient.h"
19+
#endif // __linux__
1720

1821
namespace KINETO_NAMESPACE {
1922

@@ -53,7 +56,11 @@ class DaemonConfigLoader : public IDaemonConfigLoader {
5356

5457
void setCommunicationFabric(bool enabled) override;
5558

59+
IpcFabricConfigClient* getConfigClient();
60+
5661
static void registerFactory();
62+
private:
63+
std::unique_ptr<IpcFabricConfigClient> configClient;
5764
};
5865
#endif // __linux__
5966

0 commit comments

Comments
 (0)