Skip to content

Commit

Permalink
Add a StackTraceTimeout option to set the timeout for the backtrace h…
Browse files Browse the repository at this point in the history
…andler.

Summary: This specifies the maximum number of seconds spent for generating a stack trace
when hhvm is crashed. The default is 0 which means no timeout. This can be set
to prevent from deadlocks in the backtrace handler.

Part of #4533 and #2408.
Closes #4828

Reviewed By: @markw65

Differential Revision: D1844818

Pulled By: @fredemmott
  • Loading branch information
wjywbs authored and hhvm-bot committed Feb 14, 2015
1 parent 01ef964 commit 43da36e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions hphp/doc/options.compiled
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,8 @@ next requests.
CoreDumpEmail = email address
CoreDumpReport = true
CoreDumpReportDirectory = /tmp

StackTraceTimeout = 0
}

- FullBacktrace, ServerErrorMessage, TranslateSource
Expand All @@ -612,6 +614,12 @@ file's location. ClearInputOnSuccess can automatically delete requests that
had 200 responses and it's useful to capture 500 errors on production without
capturing good responses.

- StackTraceTimeout

This specifies the maximum number of seconds spent for generating a stack trace
when hhvm is crashed. The default is 0 which means no timeout. This can be set
to prevent from deadlocks in the backtrace handler.

- APCSize

There are options for APC size profiling. If enabled, APC overall size will be
Expand Down
11 changes: 11 additions & 0 deletions hphp/runtime/base/crash-reporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ namespace HPHP {
bool IsCrashing = false;

static void bt_handler(int sig) {
if (RuntimeOption::StackTraceTimeout > 0) {
if (IsCrashing && sig == SIGALRM) {
// Raising the previous signal does not terminate the program.
signal(SIGABRT, SIG_DFL);
abort();
} else {
signal(SIGALRM, bt_handler);
alarm(RuntimeOption::StackTraceTimeout);
}
}

// In case we crash again in the signal hander or something
signal(sig, SIG_DFL);
IsCrashing = true;
Expand Down
2 changes: 2 additions & 0 deletions hphp/runtime/base/runtime-option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ bool RuntimeOption::CoreDumpReport = true;
std::string RuntimeOption::StackTraceFilename;
bool RuntimeOption::LocalMemcache = false;
bool RuntimeOption::MemcacheReadOnly = false;
int RuntimeOption::StackTraceTimeout = 0; // seconds; 0 means unlimited

bool RuntimeOption::EnableStats = false;
bool RuntimeOption::EnableAPCStats = false;
Expand Down Expand Up @@ -1409,6 +1410,7 @@ void RuntimeOption::Load(IniSetting::Map& ini, Hdf& config,

Config::Bind(LocalMemcache, ini, debug["LocalMemcache"]);
Config::Bind(MemcacheReadOnly, ini, debug["MemcacheReadOnly"]);
Config::Bind(StackTraceTimeout, ini, debug["StackTraceTimeout"], 0);

{
Hdf simpleCounter = debug["SimpleCounter"];
Expand Down
1 change: 1 addition & 0 deletions hphp/runtime/base/runtime-option.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ class RuntimeOption {
static std::string StackTraceFilename;
static bool LocalMemcache;
static bool MemcacheReadOnly;
static int StackTraceTimeout;

static bool EnableStats;
static bool EnableAPCStats;
Expand Down

0 comments on commit 43da36e

Please sign in to comment.