diff --git a/CHANGELOG b/CHANGELOG index 07060ffd18..83629cde78 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,10 @@ devel ----- +* Fix strange shutdown hanger which came from the fact that currently + libgcc/libmusl wrongly detect multi-threadedness in statically linked + executables. + * Enabled IPO with cmake as an option, default is on for release builds without google tests. diff --git a/arangod/RestServer/arangod.cpp b/arangod/RestServer/arangod.cpp index e82653d56c..01b18d2ad1 100644 --- a/arangod/RestServer/arangod.cpp +++ b/arangod/RestServer/arangod.cpp @@ -332,10 +332,35 @@ namespace arangodb { // *restartAction = myRestartAction; // arangodb::application_features::ApplicationServer::server->beginShutdown(); +#ifdef __linux__ + +// The following is a hack which is currently (September 2019) needed to +// let our static executables compiled with libmusl and gcc 8.3.0 properly +// detect that we are a multi-threaded application. +// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91737 for developments +// in gcc/libgcc to address this issue. + +static void* g(void *p) { + return p; +} + +static void gg() { +} + +static void f() { + pthread_t t; + pthread_create(&t, nullptr, g, nullptr); + pthread_cancel(t); + pthread_join(t, nullptr); + static pthread_once_t once_control = PTHREAD_ONCE_INIT; + pthread_once(&once_control, gg); +} +#endif + int main(int argc, char* argv[]) { #ifdef __linux__ - // Do not delete this! See lib/Basics/operating-system.h for details. - ThrowSomeException(); + // Do not delete this! See above for an explanation. + if (argc >= 1 && strcmp(argv[0], "not a/valid name") == 0) { f(); } #endif std::string workdir(arangodb::basics::FileUtils::currentDirectory().result()); diff --git a/lib/Basics/files.cpp b/lib/Basics/files.cpp index 1f82520a18..92e9ced942 100644 --- a/lib/Basics/files.cpp +++ b/lib/Basics/files.cpp @@ -2659,20 +2659,3 @@ bool TRI_GETENV(char const* which, std::string& value) { #endif } -////////////////////////////////////////////////////////////////////////////// -/// @brief bug fix for some race on libmusl and static linking -////////////////////////////////////////////////////////////////////////////// - -// The following function just throws an exception and catches it. This is -// used on Linux for the case that we link statically and the underlying -// C-library is libmusl. This configuration has a bug in libgcc which -// triggers a shutdown busy loop (after main), provided the very first -// exception being thrown in the life of the process happens in two threads -// at the same time. By throwing right at the beginning of main() when the -// process is still single-threaded, we circumvent this problem. -#ifdef __linux__ -void ThrowSomeException() { - try { throw 42; } catch(int const&) {}; -} -#endif - diff --git a/lib/Basics/operating-system.h b/lib/Basics/operating-system.h index 531277ed5b..c839ae72ca 100644 --- a/lib/Basics/operating-system.h +++ b/lib/Basics/operating-system.h @@ -668,15 +668,6 @@ #define TRI_uid_t uid_t #define TRI_gid_t gid_t -// The following function just throws an exception and catches it. This is -// used on Linux for the case that we link statically and the underlying -// C-library is libmusl. This configuration has a bug in libgcc which -// triggers a shutdown busy loop (after main), provided the very first -// exception being thrown in the life of the process happens in two threads -// at the same time. By throwing right at the beginning of main() when the -// process is still single-threaded, we circumvent this problem. -void ThrowSomeException(); - #endif // -----------------------------------------------------------------------------