Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node process crashes unexpectedly when referencing a weak variable inside of its GC callback #84

Open
ghost opened this issue Nov 25, 2017 · 0 comments

Comments

@ghost
Copy link

ghost commented Nov 25, 2017

Issue

The following script crashes when the garbage collector is run, without throwing an exception.
(run with --expose-gc)

const weak = require('weak');

// Never called
process.on('uncaughtException', (ex) => {
	console.error("Uncaught exception: ", ex);
});

// Keep alive
setInterval(() => null, 1000);

function foo() { this.bar = 5 };

var strongFoo = new foo();
var weakFoo = weak(strongFoo, () => {
	console.log("Foo is rip: ", weakFoo);
});

console.log("weakFoo before GC: ", weakFoo);
strongFoo = null;
global.gc();
console.log("weakFoo after GC: ", weakFoo);

results in the following when running node wrapped using nodemon:

weakFoo before GC:  foo { bar: 5 }
[nodemon] app crashed - waiting for file changes before starting...

running with node directly immediately exits after the before GC statement is printed.
Node does not crash during the after GC statement if you bypass the callback by removing the reference to 'weakFoo'.

Expected behavior.

Node does not crash unexpectedly, or throws an exception when an unsafe reference to a weak variable is made inside of the variables' callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants