always empty domain stack when handling exceptions #4621

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@cxreg
cxreg commented Jan 18, 2013

Re-filing PR #4557 based against master

Make domains a little safer by avoiding potentially unbounded stack bloat

The following code will cause the stack to grow:

var d = require("domain");

setTimeout(function() {
    console.log('domain stack length is now ' + d._stack.length);
}, 100);

d.create().run(function() {
    d.create().run(function() {
        d.create().run(function() {
            d.create().on("error", function(e) {
                console.log("caught " + e)
            }).run(function() {
                    throw new Error("died")
            })
        })
    })
})
@cxreg cxreg referenced this pull request Jan 18, 2013
Closed

Domain stack fixes #4557

@cxreg cxreg always empty domain stack when handling exceptions
Due to the nature of asyncronous programming, it's impossible to know
what will run on the next tick.  Because of this, it's not correct to
maintain domain stack state between ticks

Since the _fatalException handler is only invoked after the stack is
unwound, once it exits the tick will end.  The only reasonable thing to
do in that case is to exit *all* domains.
6f44836
@isaacs
isaacs commented Jan 18, 2013

Landed with slight style change on 14c911d. (Prefer camelCase to snake_case in general. Exceptions made for module names, like var child_process = require('child_process').)

@isaacs isaacs closed this Jan 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment