nodemon -v: 2.0.2node -v: v10.15.2nodemonAppeared suddenly. Can run nodemon, save a file once to restart the server, and then the new server seems to fail to handle any requests. When closing this server and attempting to restart it, says the address is already in use.
Can you provide sample code to replicate the bug from?
Can you provide sample code to replicate the bug from?
The issue has only popped up recently for apparently no reason (like similar issues people have mentioned in issues) but I'll see if I can make some reproducible code.
Something I've noticed: if I'm editing code and nodemon causes my server to restart twice in relatively quick succession, the first of those restarts gets caught in limbo. If I close the terminal and run netstat -ano | findstr :3000 I see 127.0.0.1:3000 TIME_WAIT. Sometimes there are several of these. Maybe it's still trying to execute some kind of "server start" code, and ends up capturing server calls that are meant to be going to the latest process of the server.
Hi,
i think i have the same/similar problem.
example project: https://github.com/finnatinform/webpack-demo
npm install
npm run start:dev
md5-f6b2e1744ccf92631a8de6218435bae3
#################################START SERVER#################################
#################################STOP SERVER#################################
events.js:167
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::3000
I tried to solve it with a delay, but delay option was not applied (I use Windows 10 64bit).
I ran into this problem too. The issue is that pstree.remy is not returning all children pids. The following pull request fixes the issue.
https://github.com/remy/pstree/pull/16/commits/31a1779cee34ce303c4ec52603770d113326ef05#diff-99e795c973932b186725b6e59c0e2f15
I got the same problem, going to downgrade nodemon to see if it helps solve the problem.
same problem. I found that it only happens ina certain case for me:
When I have the server.tsx that I'm starting the server with is in the src folder. If I have it in the project root dir, it works fine.
work: nodemon -w . -e tsx,ts -x ts-node -T test.tsx vs
does not work: nodemon -w . -e tsx,ts -x ts-node -T src/server.tsx
my global nodemon version: "version": "2.0.3"
I can confirm with version 2.0.2 and 2.0.3. I am having the same issues:
events.js:288
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::3000
The project I am working on is at this repo.
For the time being I have included a kill port script in the start script but obviously this is annoying.
When I have the
server.tsxthat I'm starting the server with is in thesrcfolder. If I have it in the project root dir, it works fine.
Same here. No problems when server.ts is at the root directory but when I place it in the src folder the error starts popping up. I'm using nodemon 2.0.3.
I got the same problem, going to downgrade nodemon to see if it helps solve the problem.
I'm using version 1.19 but I have the same issue.
If I slowly spam ctrl+s on vscode, nodemon once restarts correctly, once crashes with EADDRINUSE error.
It was working fine one week ago.
Nodejs: 12.13.1
npm: 6.12.1
OS: Arch Linux (Manjaro), kernel: 4.19.107-1
Confirmed on Node 14 on archlinux and nodemon 2.0.2. This issue appeared suddenly out of nowhere just recently when it had been always working fine before.
I think it is a problem with system speed and the way the process restart on file changes. It seems to happen too quickly and port is still running IMO.
My work around was to set port:
const port = process.env.PORT then use the variable in app.listen(port).
In package.json I changed my script:
"start": "PORT=3000 nodemon app.js"
This seems to work for now.
I haven't changed anything (maybe I restarted my machine, can't remember), but now it is working fine for me.
Same here
nodemon 2.0.3
node 13.7
Windows 10 with Ubuntu 18.04 running in WSL2
After pressing CTRL +C to kill nodemon, when running lsof -i:5000 I see a node process still running there.
@nsamarak sorry for the super late reply, but the PR you raised on pstree.remy isn't the fix. The pstree function is designed to _only_ get the sub procesess, and nodemon handles the main process here: https://github.com/remy/nodemon/blob/496c3353c45362fb5cd010b73160925659005a0d/lib/monitor/run.js#L358-L368
That's to say, this isn't the source of the problem.
@einarpersson if you provide the code that's binding to port 5000 there might be clues in there, otherwise there's no way to answer why.
@remy It seems like you missed the part of my comment where I said:
The issue is that pstree.remy is not returning all children pids.
Children pids equals subprocesses. Without the previously linked PR, pstree.remy was not returning all subprocesses and therefore not all the subprocesses were getting killed. Since one of the subprocesses that was not killed is bound to the webserver port, subsequent attempts by nodemon to start subprocesses attempting to bind to the webserver port would error out with "Error: listen EADDRINUSE: address already in use".
This is such a problem, out of frustration I have had to move on to another package.
@nsamarak I appreciate you might not have seen a fresh new issue, but the one thing that makes it near impossible to debug is a pared down example codebase. There's been only two comments that shared code, and neither were anything remotely need to pared down (one of the two contains 24 dependencies for example).
The fix PR you're pointing to solves a very very specific problem and given the vagueness of each report (again: no code) it's impossible to tell whether that particular PR will fix all your problems. My guess is that it'll fix about 20% of folks (anyone using concurrently or npm-run-all scripts, I _think_) but not others.
Case and point: this issue was raised against Windows 10 (that's all it says). The PR fix is for unix based systems using ps to track subprocesses. The PR once live (and it's not passing tests locally) won't fix this original report.
I can't help people when I don't have a solid example to run from. It's doubly frustrating when I get replies on bug reports that have nothing that moves the software closer to working the way you all need.
Most of you on this thread haven't really explained how you're using nodemon in your code (i.e. missing pared down code), but a new release the ps tree logic has been released.
To pick this up, you'll need to uninstall and re-install nodemon (i.e. a patch change in a dependency).
I'm going to close this issue on the basis that a decent number of people think it's related to the pstree logic, and in the hope that when (not if) this issue comes back it will include code to replicate.
Thanks all.
Most helpful comment
I think it is a problem with system speed and the way the process restart on file changes. It seems to happen too quickly and port is still running IMO.
My work around was to set
port:const port = process.env.PORTthen use the variable inapp.listen(port).In package.json I changed my script:
"start": "PORT=3000 nodemon app.js"This seems to work for now.