Closed awelzel closed 1 year ago
pinojs uses on-exit-leak-free as a dependency and using that alone seems to trigger the hang:
$ cat on-exit-lf.js
'use strict'
const { register, unregister } = require('on-exit-leak-free')
const obj = { foo: 'bar' };
console.log("register")
register(obj, shutdown);
function shutdown (obj, eventName) {
console.log(eventName) // beforeExit
}
console.log("done")
and after some more reducing, using FinalizationRegistry seems to be the culprit. The following already hangs without any external libraries:
$ cat on-exit-hang.js
'use strict'
function clear() {
console.log("clear");
}
const registry = new FinalizationRegistry(clear);
function onExit () {
console.log("onExit()");
}
setImmediate(() => {
let obj = {foo: 'bar'};
let ref = new WeakRef(obj);
registry.register(obj, ref);
process.on('exit', onExit);
});
Mike Peters reported that using pinojs with ZeekJS hangs the process on shutdown: In fact, it spins at 100% CPU
The following JavaScript file reproduces the issue:
Example stack trace when hanging: