HeyPuter / puter

🌐 The Internet OS! Free, Open-Source, and Self-Hostable.
https://puter.com
GNU Affero General Public License v3.0
26.84k stars 1.84k forks source link

`npm start` leaves webpack processes lying around #347

Open AtkinsSJ opened 7 months ago

AtkinsSJ commented 7 months ago

Noticed this initially when I started getting a whole bunch of errors like this when running npm start:

[INFO::__dev-watcher] (3.967s) [puter.js:webpack-watch:err] Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/home/sam/Projects/HeyPuter/puter/packages/puter-js'

I'd been repeatedly starting puter, then stopping it with Ctrl-C, to test some changes I was making.

Sure enough, looking at the process monitor, I had a lot of webpack processes still around from previous npm starts. It seems that however they are spawned, they don't die with the parent process.

AtkinsSJ commented 7 months ago

The EMFILE error might have been caused by some of my local changes, but the webpack issue isn't.

KernelDeimos commented 7 months ago

I was worried this might happen. I actually have no idea how to make sure child processes actually exit in node - maybe it can't be done? Maybe we need to record PIDs and invoke the kill command on the exit handler? I'm adding the "help wanted" label to this.

Eric-Lighthall commented 7 months ago

It looks like this might be specific to UNIX with using spawn and shell:true.

Adding detached: true in spawn and using process.kill(-proc.pid) seems to work, but I'm not entirely sure if this alters some behavior that we don't want.

Here's something related I found. Issue #46865 in Node.

KernelDeimos commented 3 weeks ago

Added need-reprod label as I have not ever reproduced this issue