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

Dev environment: Node server is unable to start, error includes EADDRINUSE: 8000 #983

Closed
louh opened this issue May 16, 2018 · 4 comments
Closed

Comments

@louh
Copy link
Member

@louh louh commented May 16, 2018

For anyone running Streetmix in a dev environment (observed in Mac OSX), sometimes a Node server does not shut down cleanly, which means the next time you run npm start to restart the server, Node continually crashes with an error message that includes the large error code EADDRINUSE: 8000 (something like this). This issue documents a workaround and creates a call-to-action to invite an investigation and possible long term solution into the problem.

Workaround

If you are currently trapped in the EADDRINUSE error loop, force the current process to end with Control-C.

Run npm stop to make sure any child processes are killed.

Next, we need to find the previous zombie process. We know it's still running on port 8000. Run:

lsof -i :8000

Sometimes you will see a long list of processes including Google Chrome and node. You want the PID of the node process. It can be any number.

Run this command, where x is the PID number:

kill x

This should remove the zombie process. The next time you run npm start, things should be working as normal.

Investigation

It is not entirely clear why this occurs. It does not appear to be the result of failing to close the process when asked, but sometimes the process simply "hangs" and drops you back onto a terminal prompt, although the process continues to run in the background. This can happen when the dev server has been running for a long period of time.

For people working long-term on Streetmix this occurs frequently enough to be a common problem.

Questions:

  • Is this a Node problem?
  • Is this an Express server problem?
  • Is this an effect of how we watch (supervise) the process? Is this related to spawning a child process for MongoDB?
  • Does this occur on any other OS? (e.g. Windows, Linux)
@Ayush-Rawal
Copy link
Contributor

@Ayush-Rawal Ayush-Rawal commented May 19, 2018

@louh

  • Yes

  • Yes, it is the server causing the problem but it is not due to the express framework

    1. Unlikely
    2. No
  • Yes it does

EADDRINUSE is thrown when another process is utilizing the port you're trying to connect to. In this case it is due to the node process continuing to run in the background.

I don't know of a solution to this except manually killing the process.

To stop this I'd recommend using
kill -s 15 <PID>
instead of
kill <PID>

The difference being that kill by default sends SIGKILL (9) signal, whose behavior is to kill the process immediately. SIGTERM (15) also kill the process but allows it a chance to end gracefully (i.e. giving the process a chance to clean up)

@louh
Copy link
Member Author

@louh louh commented May 22, 2018

Would it be possible to restore the process back into the foreground?

@Ayush-Rawal
Copy link
Contributor

@Ayush-Rawal Ayush-Rawal commented May 26, 2018

Not by any way I'm aware of.

@louh
Copy link
Member Author

@louh louh commented Aug 3, 2019

A note about this problem has been added to troubleshooting documentation, here: 4ba2dfc.

I'll close this now.

@louh louh closed this as completed Aug 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants