Skip to content

Commit

Permalink
Turn pause_and_exit() into pause_forever()
Browse files Browse the repository at this point in the history
Summary:
pthread_exit can lead to confusing crashes for us: it raises
a "forced unwind", which it seems (strangely) will enter into C++
catch (...) blocks: but if you don't rethrow from one these blocks,
glibc will call abort() from a function called unwind_cleanup.  Our
LibEventWorker has a catch block of this sort that doesn't rethrow, so
calling pthread_exit below there will abort the program.  (The point
of this function is to just wait while another thread writes a
stacktrace file, so there's no reason to exit the thread.)
  • Loading branch information
jdelong authored and Joel Pobar committed Sep 27, 2012
1 parent 7c67d64 commit a740eb0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
15 changes: 7 additions & 8 deletions src/runtime/base/builtin_functions.cpp
Expand Up @@ -1000,14 +1000,13 @@ Object create_object(CStrRef s, CArrRef params, bool init /* = true */,
}
}

void pause_and_exit() {
// NOTE: This is marked as __attribute__((noreturn)) in base/types.h
// Signal sent, nothing can be trusted, don't do anything, as we might
// write bad data, including calling exit handlers or destructors until the
// signal handler (StackTrace) has had a chance to exit.
sleep(300);
// Should abort first, but it not try to exit
pthread_exit(0);
/*
* This function is used when another thread is segfaulting---we just
* want to wait forever to give it a chance to write a stacktrace file
* (and maybe a core file).
*/
void pause_forever() {
for (;;) sleep(300);
}

void check_request_surprise(ThreadInfo *info) {
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/base/types.h
Expand Up @@ -397,21 +397,21 @@ inline void check_recursion(ThreadInfo *&info) {
}

// implemented in runtime/base/builtin_functions.cpp
extern void pause_and_exit() ATTRIBUTE_COLD ATTRIBUTE_NORETURN;
extern void pause_forever() ATTRIBUTE_COLD ATTRIBUTE_NORETURN;
extern void check_request_surprise(ThreadInfo *info) ATTRIBUTE_COLD;

extern bool SegFaulting;

inline void check_request_timeout(ThreadInfo *info) {
const_assert(!hhvm);
if (SegFaulting) pause_and_exit();
if (SegFaulting) pause_forever();
info->m_mm->refreshStats();
if (info->m_reqInjectionData.conditionFlags) check_request_surprise(info);
}

inline void check_request_timeout_nomemcheck(ThreadInfo *info) {
const_assert(!hhvm);
if (SegFaulting) pause_and_exit();
if (SegFaulting) pause_forever();
if (info->m_reqInjectionData.conditionFlags) check_request_surprise(info);
}

Expand Down

0 comments on commit a740eb0

Please sign in to comment.