Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use SIGABRT if process.abort isn't available

  • Loading branch information...
commit ac77f3a546c16b0e19fa53c46d135967b1680f1e 1 parent 427589f
@davepacheco davepacheco authored
Showing with 36 additions and 11 deletions.
  1. +35 −10 lib/panic.js
  2. +1 −1  package.json
View
45 lib/panic.js
@@ -26,11 +26,34 @@
var mod_fs = require('fs');
var mod_subr = require('./subr');
+var caPanicSkipDump = false;
+var caPanicAbort = false;
+
/*
* Configures the current program to dump saved program state before crashing.
+ * The following options may be specified:
+ *
+ * abortOnPanic On panic, uses process.abort() (which is abort(3C)) to
+ * exit the program. On some systems, this causes the OS
+ * to save a core file that can be used to read JavaScript-
+ * level state. If process.abort isn't available, SIGABRT
+ * will be used instead.
+ *
+ * skipDump On panic, skips attempting to dump JavaScript-level
+ * state in JavaScript. This is mostly useful if you've
+ * also set abortOnPanic, in which case you expect to
+ * extract JavaScript-level state from the OS core dump and
+ * don't want node-panic to even try to serialize state
+ * separatley.
*/
-function caEnablePanicOnCrash()
+function caEnablePanicOnCrash(options)
{
+ if (options && options.abortOnPanic)
+ caPanicAbort = true;
+
+ if (options && options.skipDump)
+ caPanicSkipDump = true;
+
process.on('uncaughtException', function (ex) {
caPanic('panic due to uncaught exception', ex);
});
@@ -70,22 +93,24 @@ function caPanic(str, err)
* If we had child.execSync(), we could get pfiles. :(
*/
- caPanicLog('writing core dump to ' + process.cwd() + '/' +
- filename);
- caPanicSave(filename);
- caPanicLog('finished writing core dump');
+ if (!caPanicSkipDump) {
+ caPanicLog('writing core dump to ' + process.cwd() +
+ '/' + filename);
+ caPanicSave(filename);
+ caPanicLog('finished writing core dump');
+ }
} catch (ex) {
caPanicWriteSafeError('error during panic', ex);
}
- /*
- * If available, use process.abort() to dump core. Some systems
- * (notably illumos-based systems) can debug Node core dumps.
- */
+ if (!caPanicAbort)
+ process.exit(1);
+
if (process.abort)
process.abort();
- process.exit(1);
+ for (;;)
+ process.kill(process.pid, 'SIGABRT');
}
/*
View
2  package.json
@@ -1,6 +1,6 @@
{
"name": "panic",
- "version": "0.1.2",
+ "version": "0.2.0",
"description": "Postmortem debugging facility",
"author": "Joyent (joyent.com)",
"engines": { "node": "*" },
Please sign in to comment.
Something went wrong with that request. Please try again.