Permalink
Browse files

fixing #561 deadlock on handling crash at memory operations

  • Loading branch information...
tomatolog committed Nov 13, 2018
1 parent 15b25a9 commit 85d30a232d4ffd89916b673a9b2db946d272a945
Showing with 24 additions and 1 deletion.
  1. +1 −0 src/searchd.cpp
  2. +20 −1 src/sphinxutils.cpp
  3. +3 −0 src/sphinxutils.h
@@ -1690,6 +1690,7 @@ SphCrashLogger_c::~SphCrashLogger_c () { sphThreadSet ( m_tTLS, NULL ); }
void SphCrashLogger_c::Init ()
{
sphBacktraceInit();
Verify ( sphThreadKeyCreate ( &m_tTLS ) );
}
@@ -2165,6 +2165,7 @@ static const char g_sSourceTail[] = "> source.txt\n";
static const char * g_pArgv[128] = { "addr2line", "-e", "./searchd", "0x0", NULL };
static char g_sNameBuf[512] = {0};
static CSphString g_sBinaryName;
static bool g_bDumpGDB = true;
bool IsDebuggerPresent()
{
@@ -2483,7 +2484,8 @@ void sphBacktrace ( int iFD, bool bSafe )
"Look into the chapter 'Reporting bugs' in the documentation\n"
"(http://docs.manticoresearch.com/latest/html/reporting_bugs.html)" );
if ( DumpGdb ( iFD ) )
// wo jemalloc allocator might deadlock in case of crash at free function
if ( g_bDumpGDB && DumpGdb ( iFD ) )
return;
// convert all BT addresses to source code lines
int iCount = Min ( iDepth, (int)( sizeof(g_pArgv)/sizeof(g_pArgv[0]) - SPH_BT_ADDRS - 1 ) );
@@ -2576,6 +2578,19 @@ void sphBacktraceSetBinaryName ( const char * sName )
g_pArgv[SPH_BT_BINARY_NAME] = g_sBinaryName.cstr();
}
void sphBacktraceInit()
{
#if HAVE_BACKTRACE
backtrace ( g_pBacktraceAddresses, SPH_BACKTRACE_ADDR_COUNT );
#endif // !HAVE_BACKTRACE
// check that jemalloc is present
#if HAVE_DLOPEN
void * fnJMalloc = dlsym ( RTLD_DEFAULT, "mallctl" );
g_bDumpGDB = ( fnJMalloc!=nullptr );
#endif
}
#else // USE_WINDOWS
const char * DoBacktrace ( int, int )
@@ -2614,6 +2629,10 @@ void sphBacktraceSetBinaryName ( const char * )
{
}
void sphBacktraceInit()
{
}
#endif // USE_WINDOWS
@@ -251,6 +251,9 @@ void sphBacktrace ( int iFD, bool bSafe=false );
void sphBacktrace ( EXCEPTION_POINTERS * pExc, const char * sFile );
#endif
/// dummy call of backtrace to alloc internal structures and prevent deadlock at malloc on crash
void sphBacktraceInit();
void sphBacktraceSetBinaryName ( const char * sName );
/// plain backtrace - returns static buffer with the text of the call stack

0 comments on commit 85d30a2

Please sign in to comment.