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

Killing the parent "yarn start" process leaves the sub-sub-process that actually listens to port 3000 still running #11264

Open
haraldme opened this issue Aug 1, 2021 · 4 comments

Comments

@haraldme
Copy link

haraldme commented Aug 1, 2021

Describe the bug

Programmatically trying to kill the "yarn start" process only kills some of the relevant processes. In particular, the node sub-process that listens to port 3000 is left running, which in turn causes trouble on the next "yarn start" attempt.

Did you try recovering your dependencies?

Bug happens when running "yarn start" from fresh "npx create-react-app", so this should not be relevant.

Which terms did you search for in User Guide?

Tried searching for "stop", to see if there was some documented way of stopping the thing you start with "yarn start", but found nothing.

Environment

Environment Info:

current version of create-react-app: 4.0.3
running from /Users/hmeland/.npm/_npx/c67e74de0542c87c/node_modules/create-react-app

System:
OS: macOS 10.15.7
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Binaries:
Node: 16.6.0 - /usr/local/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 7.19.1 - /usr/local/bin/npm
Browsers:
Chrome: 92.0.4515.107
Edge: Not Found
Firefox: Not Found
Safari: 14.1.2
npmPackages:
react: ^17.0.2 => 17.0.2
react-dom: ^17.0.2 => 17.0.2
react-scripts: 4.0.3 => 4.0.3
npmGlobalPackages:
create-react-app: Not Found

Steps to reproduce

To reproduce (I'm on OSX, don't know whether other OSes are also affected):

$ npx create-react-app repro
$ cd repro/
$ yarn
$ yarn start &
[1] 94708
  # Now, wait for browser page to open and start working...

$ pstree 94708
-+= 94708 hmeland node /usr/local/Cellar/yarn/1.22.10/libexec/bin/yarn.js start
 \-+- 94730 hmeland /usr/local/Cellar/node/16.6.0/bin/node /private/tmp/repro/node_modules/.bin/react-scripts start
   \--- 94731 hmeland /usr/local/Cellar/node/16.6.0/bin/node /private/tmp/repro/node_modules/react-scripts/scripts/start.js

$ sudo lsof -i :3000 | grep LISTEN
node    94731 hmeland   27u  IPv4 0xe4aa337aee33c393      0t0  TCP *:hbci (LISTEN)
  # Note that the process listening to port 3000 (pid 94708)
  # is not the master "yarn start" process (pid 94731)

  # If we had run "yarn start" in the foreground, and quit it with
  # Control-C, that ends up killing both all of the relevant processes.
  # However, I'm trying to script starting/stopping the development
  # web server in concert with my backend service, so naively I only
  # have the master "yarn start" process to work with (unless I want
  # to put my hands into a hornets' nest of OS-specific
  # workarounds).

$ kill 94708
[1]+  Terminated: 15          yarn start
$ pstree 94708
  # No output, as the parent process has been killed
  # ... but the listening node subprocess is still running:
$ sudo lsof -i :3000 | grep LISTEN
node    94731 hmeland   27u  IPv4 0xe4aa337af94349b3      0t0  TCP *:hbci (LISTEN)

Expected behavior

Killing the parent process should also cause the listening sub-process to get killed.

Actual behavior

(Write what happened. Please add screenshots!)

Reproducible demo

(Paste the link to an example project and exact instructions to reproduce the issue.)

@razwanizmi
Copy link

I have a fix for this, but I'm not sure if it will work for everyone. Maybe you can try it out?

Open up node_modules/react-scripts/scripts/start.js and add this line before any process.on is called (line 18 on the current main branch works).

process.stdin.resume()

This fixed the issue for me, and I've tried to describe it more in my issue here.

@OurMajesty
Copy link

@razwanizmi adding process.stdin.resume(); before line 18 didn't help me unfortunately (Windows 11, Node 14)

@haraldme
Copy link
Author

@razwanizmi I have tried your suggested fix (Sorry for the slow response), but it does not fix my issue.

If I try reproducing my issue as originally described, I end up with a parent process that gets "stopped" because it is unable to read from stdin, but I think that is more an artifact of my attempted shell reproduction of the issue than the issue itself.

By modifying my reproduction steps to do "yarn start < /dev/null &" instead of just "yarn start &", I still see the same parent-process-gets-killed-but-sub-sub-process-which-is-actually-listening-to-port-3000-sticks-around behaviour that I originally described.

@stale
Copy link

stale bot commented Jan 9, 2022

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants