labring / labring/laf

[bug] Dependency uploading may result in zombie processes left behind

Open
#1,972 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
7.6k
Forks
670
PR merge metrics
No merged PRs in 30d

Description

### Search before asking

- [X] I had searched in the [issues](https://github.com/labring/laf/issues?q=is%3Aissue) and found no similar issues.

### Environment

https://laf.dev

### What happened

Sometimes when running Laf containers, there would be several zombie processes on the system.
And when checking inside the container, we could see that these zombie processes indeed come from Laf:
```sh
$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
node 1 0.2 0.1 1367068 108608 ? Ssl May11 8:13 node --max_old_space_size=204 --max-http-header-size=1048576 --experimental-vm-modules --experimental-fetch ./dist/index.js
node 45 0.0 0.0 0 0 ? Z May11 0:00 [sh]
node 73 0.0 0.0 0 0 ? Z May11 0:00 [sh]
```
After debugging, I suspect that the problem was caused by the following piece of code:
https://github.com/labring/laf/blob/f0c7a5864a42ed9d7cdcfcf50053832becf321f4/runtimes/nodejs/src/support/module-hot-reload.ts#L94C1-L99C30.

The whole logic is run inside a background grandchild process of `node`, which is not directly handled by `node`.
As a result, the process reaping job (wait) needs to be manually done inside the shell, according to [the documentation](https://manpages.ubuntu.com/manpages/focal/man1/sh.1.html):
> If a command is terminated by the control operator ampersand (&), the shell executes the command asynchronously -- that is, the shell does not wait for the command to finish before executing the next command.

The above code does not handle process reaping inside the shell, hence the zombie processes linger.

### How to reproduce

1. Run a Laf container
2. Get a shell of the container with `kubectl exec`, `docker exec`, etc
3. Run `ps aux` and observe

### Are you willing to submit PR?

- [ ] Yes I am willing to submit a PR!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.