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

processes remaining open and leaking memory after killing main process #7852

Open
sysrage opened this issue Mar 10, 2022 · 7 comments
Open
Labels
bug has-min-repro Has a minimum reproduction nw2

Comments

@sysrage
Copy link

sysrage commented Mar 10, 2022

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

  1. Put the following files in a directory.
  2. Run: node test.js
  3. Press CTRL+C in the terminal where step 2 was execute.
  4. Note that the NW.js application will "quit" but sometimes phantom nw.exe processes will remain running.
  5. Watch those phantom nw.exe processes 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;
});
@nebular
Copy link

nebular commented Mar 18, 2022

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.

@panther7
Copy link

We has same issue, crash or running some process after "close" app.

@rogerwang

@jonlepage
Copy link

long discutions and theory over there
#7633

@sysrage
Copy link
Author

sysrage commented Apr 26, 2022

long discutions and theory over there #7633

no solution, though. @rogerwang can you let us know what's needed to get this behavior fixed?

@jonlepage
Copy link

jonlepage commented Apr 26, 2022

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 !....

@sysrage
Copy link
Author

sysrage commented Apr 26, 2022

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".

@nebular
Copy link

nebular commented Apr 30, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug has-min-repro Has a minimum reproduction nw2
Projects
None yet
Development

No branches or pull requests

5 participants