Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Memory leak in domain stack when error occurs in nested domain #3836

mikeatemotive opened this Issue Aug 6, 2012 · 5 comments


None yet
3 participants

Consider the following code:

var domain = require('domain');

function handleError1(error) {
    console.log("Error: " + error);

function handleError2(error) {
    console.log("Error: " + error);

var d1 = domain.createDomain("d1");
var d2 = domain.createDomain("d2");

d1.on("error", handleError1);
d2.on("error", handleError2);


d1.run(function() {
    d2.run(function() {
        throw new Error("thrown from nested domain");

function showDomainStack() {

When run, it shows that the domain d1 is still on the domain stack when the next event is processed. Since it will never be removed, it can't be garbage collected.


bnoordhuis commented Aug 13, 2012

/cc @isaacs

This is fixed in 0.9.8, I'm guessing by the change

domain: empty stack on all exceptions (Dave Olszewski) 

isaacs commented Jan 29, 2013

We can't really fix this in 0.8 too easily, without changing semantics, and it's fixed in master, so I'm closing this.

@isaacs isaacs closed this Jan 29, 2013

I'd suggest that the semantics are broken in 0.8 (they amount to "an event may be processed under a random domain"), but, personally, I can wait for 0.10.

isaacs commented Jan 29, 2013

I guess we could backport that fix. It'd have to be rewritten, though, because the code has moved around a bunch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment