nw.js
nw.js copied to clipboard
processes remaining open and leaking memory after killing main process
NWJS Version : 0.62.0 Operating System : Windows 10
Expected behavior
When the main nw.exe process is killed, all child processes should also be killed. No nw.exe processes should continue leaking memory until the system crashes.
Actual behavior
Intermittently, 2-3 nw.exe processes will remain running after the "main" process is terminated. When this happens, those processes will continue increasing memory usage until the system runs out of memory and begins killing active processes.
How to reproduce
- Put the following files in a directory.
- Run:
node test.js - Press CTRL+C in the terminal where step 2 was execute.
- Note that the NW.js application will "quit" but sometimes phantom
nw.exeprocesses will remain running. - Watch those phantom
nw.exeprocesses slowly chew through all available system memory.
package.json
{
"name": "bug",
"main": "bug.html"
}
bug.html
Hello
test.js
const { spawn } = require('child_process');
// Launch NW.js application
const proc = spawn('nw', ['.']);
console.log(`PID of child_process.exec() process: ${proc.pid}`);
// Kill app on CTRL+C
process.on('SIGINT', () => {
process.kill(proc.pid);
process.exit();
})
// Keep alive until NW.js application exits
let quit = false;
const keepAliveCallback = () => {
if (!quit) setTimeout(keepAliveCallback, 500);
};
keepAliveCallback();
proc.stdout.on('data', (data) => {
process.stdout.write(data);
});
proc.stderr.on('data', (data) => {
process.stderr.write(data);
});
proc.on('exit', () => {
quit = true;
});
happening to me as well kind of frequently, i also spawn processes & use stdin, stderr, etc .. but also happens without those things involved - currently investigating if related to media streams open, event handlers between main & renderer or objects shared between renderers ... i am clueless really but would be glad to help to find the issue. Also wondering if a workaround would be possible, so after the application exits a script kills the helper processes if they stay alive.
We has same issue, crash or running some process after "close" app.
@rogerwang
long discutions and theory over there https://github.com/nwjs/nw.js/issues/7633
long discutions and theory over there #7633
no solution, though. @rogerwang can you let us know what's needed to get this behavior fixed?
no solution, though. @rogerwang can you let us know what's needed to get this behavior fixed?
the only solution i use is taskkill /F /IM nw.exe /T 🤣
Is dirty and not pro but no one have hint where this come from !....
the only solution i use is
taskkill /F /IM nw.exe /T🤣 Is dirty and not pro but no one have hint where this come from !....
Unfortunately, that is not a solution. It's an ugly workaround that doesn't work in many cases. That also kills valid nw.exe processes (from other apps), so can't be done "automatically".
my application creates a socket server on the main process which renderers then connect to - funny thing is, if there has been a previous dirty exit with hung renderers, if you reopen the application, the new instance´s renderers connect to the older instance socket server, in the main thread that should not exist - so it also stays alive in my case and apparently responsive - however I cannot connect a debugger to it or its former renderers - the debugger does not connect.