Skip to content

Instantly share code, notes, and snippets.

@Narnach
Created October 19, 2012 11:30
Show Gist options
  • Select an option

  • Save Narnach/3917713 to your computer and use it in GitHub Desktop.

Select an option

Save Narnach/3917713 to your computer and use it in GitHub Desktop.
diff --git a/ext/common/ApplicationPool2/Pool.h b/ext/common/ApplicationPool2/Pool.h
index e5cd3a8..82ca754 100644
--- a/ext/common/ApplicationPool2/Pool.h
+++ b/ext/common/ApplicationPool2/Pool.h
@@ -482,6 +482,14 @@ public:
typedef shared_ptr<ProcessAnalyticsLogEntry> ProcessAnalyticsLogEntryPtr;
void collectAnalytics(ev::timer &timer, int revents) {
+ try {
+ realCollectAnalytics(timer);
+ } catch (const tracable_exception &e) {
+ P_WARN("ERROR: " << e.what() << "\n Backtrace:\n" << e.backtrace());
+ }
+ }
+
+ void realCollectAnalytics(ev::timer &timer) {
PoolPtr self = shared_from_this(); // Keep pool object alive.
TRACE_POINT();
this_thread::disable_interruption di;
diff --git a/ext/common/EventedMessageServer.h b/ext/common/EventedMessageServer.h
index 2659db9..add164c 100644
--- a/ext/common/EventedMessageServer.h
+++ b/ext/common/EventedMessageServer.h
@@ -97,11 +97,13 @@ public:
void writeArrayMessage(StaticString args[], unsigned int count) {
char headerBuf[sizeof(uint16_t)];
unsigned int outSize = ArrayMessage::outputSize(count);
- StaticString *out = (StaticString *)
- alloca(outSize * sizeof(StaticString));
+ SmallVector<StaticString, 10> out;
+ out.reserve(outSize);
+ //StaticString *out = (StaticString *)
+ // alloca(outSize * sizeof(StaticString));
- ArrayMessage::generate(args, count, headerBuf, out, outSize);
- write(out, outSize);
+ ArrayMessage::generate(args, count, headerBuf, &out[0], outSize);
+ write(&out[0], outSize);
}
};
diff --git a/ext/common/agents/Base.cpp b/ext/common/agents/Base.cpp
index cd7737a..4009b0a 100644
--- a/ext/common/agents/Base.cpp
+++ b/ext/common/agents/Base.cpp
@@ -79,6 +79,8 @@ static const char digits[] = {
static const char hex_chars[] = "01234567890abcdef";
static bool shouldDumpWithCrashWatch = true;
+static bool sleepOnCrash = false;
+static bool beepOnCrash = false;
// Pre-allocate an alternative stack for use in signal handlers in case
// the normal stack isn't usable.
@@ -545,6 +547,17 @@ static void
abortHandler(int signo, siginfo_t *info, void *ctx) {
pid_t pid = getpid();
pid_t child;
+
+ if (sleepOnCrash) {
+ safePrintErr("Process crashed! Sleeping...\n");
+ child = asyncFork();
+ if (child == 0) {
+ resetSignalHandlersAndMask();
+ execlp("osascript", "osascript", "-e", "beep 2", 0);
+ _exit(1);
+ }
+ raise(SIGSTOP);
+ }
// It isn't safe to call any waiting functions in this signal handler,
// not even read() and waitpid() even though they're async signal safe.
@@ -638,6 +651,9 @@ installAbortHandler() {
sigaction(SIGSEGV, &action, NULL);
sigaction(SIGBUS, &action, NULL);
sigaction(SIGFPE, &action, NULL);
+
+ sleepOnCrash = hasEnvOption("PASSENGER_SLEEP_ON_CRASH", false);
+ beepOnCrash = hasEnvOption("PASSENGER_BEEP_ON_CRASH", false);
}
void
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment