question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

processes remaining open and leaking memory after killing main process

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
sysragecommented, 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”.

0reactions
nebularcommented, May 1, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - possible for a process to result in leaked memory after it is ...
Killing the parent process doesn't in itself guarantee that the child processes will terminate. This could look like a memory leak.
Read more >
Physical Memory Leak by Terminated Processes - TechNet
So any process terminates, does not release 20K of Physical Memory and gradually, server crashes when complete Memory chews up. We did some...
Read more >
How we find and fix OOM and memory leaks in Java Services
Unclosed streams and connections represent another cause for memory leaks. In general, the operating system only allows a limited number of open ...
Read more >
Zombie Processes are Eating your Memory | Random ASCII
So, a zombie process is a process that has shut down but is kept around because some other still-running process holds a handle...
Read more >
Memory leak - Wikipedia
In computer science, a memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found