Skip to content

Commit 7be88cc

Browse files
Merge pull request ClickHouse#63548 from azat/fix-sentry-crash-on-exit
Fix crash on exit with sentry enabled (due to openssl destroyed before sentry)
2 parents 3ac5853 + 27b4165 commit 7be88cc

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/Daemon/BaseDaemon.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,8 @@ BaseDaemon::~BaseDaemon()
706706
}
707707

708708
signal_pipe.close();
709+
710+
SentryWriter::resetInstance();
709711
}
710712

711713

src/Daemon/SentryWriter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ SentryWriter * SentryWriter::getInstance()
7272
{
7373
return SentryWriter::instance.get();
7474
}
75+
void SentryWriter::resetInstance()
76+
{
77+
SentryWriter::instance.reset();
78+
}
7579

7680
SentryWriter::SentryWriter(Poco::Util::LayeredConfiguration & config)
7781
{
@@ -254,6 +258,7 @@ void SentryWriter::sendError(Type type, int sig_or_error, const std::string & er
254258

255259
void SentryWriter::initializeInstance(Poco::Util::LayeredConfiguration &) {}
256260
SentryWriter * SentryWriter::getInstance() { return nullptr; }
261+
void SentryWriter::resetInstance() {}
257262

258263
SentryWriter::SentryWriter(Poco::Util::LayeredConfiguration &) {}
259264
SentryWriter::~SentryWriter() = default;

src/Daemon/SentryWriter.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ class SentryWriter
2222

2323
/// Initialize static SentryWriter instance
2424
static void initializeInstance(Poco::Util::LayeredConfiguration & config);
25+
2526
/// @return nullptr if initializeInstance() was not called (i.e. for non-server) or SentryWriter object
2627
static SentryWriter * getInstance();
2728

29+
/// SentryWriter static instance should be reset explicitly to avoid
30+
/// possible use-after-free, since it may use some global objects (i.e.
31+
/// OpenSSL), while sending final statistics
32+
/// (SENTRY_SESSION_STATUS_EXITED).
33+
static void resetInstance();
34+
2835
void onSignal(
2936
int sig,
3037
const std::string & error_message,

0 commit comments

Comments
 (0)