Merge pull request #23616 from ClickHouse/tsan-segfault-shutdown

Fix segfault in TSan on _exit
This commit is contained in:
alexey-milovidov 2021-04-25 10:33:34 +03:00 committed by GitHub
commit 4fd56ef472
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,6 +14,7 @@
#include <Poco/Net/NetException.h>
#include <Poco/Util/HelpFormatter.h>
#include <ext/scope_guard.h>
#include <common/defines.h>
#include <common/logger_useful.h>
#include <common/phdr_cache.h>
#include <common/ErrorHandlers.h>
@ -86,6 +87,8 @@
# include <sys/mman.h>
# include <sys/ptrace.h>
# include <Common/hasLinuxCapability.h>
# include <unistd.h>
# include <sys/syscall.h>
#endif
#if USE_SSL
@ -426,6 +429,19 @@ void checkForUsersNotInMainConfig(
}
[[noreturn]] void forceShutdown()
{
#if defined(THREAD_SANITIZER) && defined(OS_LINUX)
/// Thread sanitizer tries to do something on exit that we don't need if we want to exit immediately,
/// while connection handling threads are still run.
(void)syscall(SYS_exit_group, 0);
__builtin_unreachable();
#else
_exit(0);
#endif
}
int Server::main(const std::vector<std::string> & /*args*/)
{
Poco::Logger * log = &logger();
@ -1435,7 +1451,7 @@ int Server::main(const std::vector<std::string> & /*args*/)
/// Dump coverage here, because std::atexit callback would not be called.
dumpCoverageReportIfPossible();
LOG_INFO(log, "Will shutdown forcefully.");
_exit(Application::EXIT_OK);
forceShutdown();
}
});