Skip to content

Commit 6216702

Browse files
committed
fix: exit server after reconfiguring
According to [the docs][1], `exitOnUncaughtException` should: > Exit the process after handling an uncaught exception. Requires > `captureUncaught` to also be set. So with this config: ````js var rollbar = new Rollbar({ captureUncaught: true, exitOnUncaughtException: true, // ... }); ``` ...an uncaught exception should exit the process. This works correctly, but *only* if `rollbar.configure()` is *never* called again, because: 1. `exitOnUncaughtException` [was deleted][2] from our options 2. Calling `configure()` calls [`setupUnhandledCapture()`][3]... 3. ...which calls [`handleUncaughtExceptions()`][4]... 4. ...which now [tries to access][5] `options.exitOnUncaughtException` 5. But this option was deleted in Step 1, so when we [replace][6] our `uncaughtException` handler, we now have `exitOnUncaught = false` This change: - no longer deletes `exitOnUncaughtException` from options (it's unclear why this is the only option that is deleted) - directly accesses `options.exitOnUncaughtException` in the handler, just like `options.captureUncaught` is accessed directly [1]: https://docs.rollbar.com/docs/rollbarjs-configuration-reference#context-1 [2]: https://github.com/rollbar/rollbar.js/blob/e964ecbdb16a4d2b8b5feaa8b70a2ec327648ed0/src/server/rollbar.js#L587 [3]: https://github.com/rollbar/rollbar.js/blob/e964ecbdb16a4d2b8b5feaa8b70a2ec327648ed0/src/server/rollbar.js#L118 [4]: https://github.com/rollbar/rollbar.js/blob/e964ecbdb16a4d2b8b5feaa8b70a2ec327648ed0/src/server/rollbar.js#L578 [5]: https://github.com/rollbar/rollbar.js/blob/e964ecbdb16a4d2b8b5feaa8b70a2ec327648ed0/src/server/rollbar.js#L586 [6]: https://github.com/rollbar/rollbar.js/blob/e964ecbdb16a4d2b8b5feaa8b70a2ec327648ed0/src/server/rollbar.js#L589
1 parent e964ecb commit 6216702

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/server/rollbar.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,6 @@ Rollbar.prototype.setupUnhandledCapture = function () {
583583
};
584584

585585
Rollbar.prototype.handleUncaughtExceptions = function () {
586-
var exitOnUncaught = !!this.options.exitOnUncaughtException;
587-
delete this.options.exitOnUncaughtException;
588-
589586
addOrReplaceRollbarHandler('uncaughtException', function (err) {
590587
if (!this.options.captureUncaught && !this.options.handleUncaughtExceptions) {
591588
return;
@@ -597,7 +594,7 @@ Rollbar.prototype.handleUncaughtExceptions = function () {
597594
logger.error(err);
598595
}
599596
});
600-
if (exitOnUncaught) {
597+
if (this.options.exitOnUncaughtException) {
601598
setImmediate(function () {
602599
this.wait(function () {
603600
process.exit(1);

test/server.rollbar.test.js

+32
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,38 @@ vows.describe('rollbar')
550550
assert.equal(logStub.getCall(0).args[0].err.message, 'node error');
551551
}
552552
notifier.log.restore();
553+
},
554+
'exitOnUncaughtException': {
555+
topic: function () {
556+
var rollbar = new Rollbar({
557+
accessToken: 'abc123',
558+
captureUncaught: true,
559+
exitOnUncaughtException: true
560+
});
561+
rollbar.exitStub = sinon.stub(process, 'exit');
562+
563+
nodeThrow(rollbar, this.callback);
564+
},
565+
'should exit': function (r) {
566+
var calls = r.exitStub.getCalls();
567+
r.exitStub.restore();
568+
assert.equal(calls.length, 1);
569+
},
570+
'unrelated option reconfigured': {
571+
topic: function(r) {
572+
r.configure({
573+
environment: 'new-env'
574+
});
575+
r.exitStub = sinon.stub(process, 'exit');
576+
577+
nodeThrow(r, this.callback);
578+
},
579+
'should exit': function(r) {
580+
var calls = r.exitStub.getCalls();
581+
r.exitStub.restore();
582+
assert.equal(calls.length, 1);
583+
}
584+
}
553585
}
554586
}
555587
}

0 commit comments

Comments
 (0)