Skip to content

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

Open
@sysrage

Description

@sysrage

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;
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions