dev uncaught exception: listen EADDRINUSE: address already in use :::5000 - node.js

I am getting the above error
[nodemon] starting `ts-node index.ts`
dev uncaught exception: listen EADDRINUSE: address already in use :::5000 +0ms
[nodemon] app crashed - waiting for file changes before starting...
I tried to find the pid with sudo lsof -i :5000
then kill -9
But then a new process pops up at the same port again. It keeps happening infinitely so I found the parent process with pid 1 and killed it and laptop restarted.
I am unable to run my node app on 5000. Any suggestions?
Edit: My repo is a node app at the root level and has a client folder which is the react app.

Related

Is there a way to restore a killed process?

I'm trying to start httpd on my web server but when I try to start it, I was getting "httpd (pd 10989) already running", so I killed the process in hopes httpd might start up. No luck.
Now I am getting:
Starting HTTPD
(98)Address already in use: AH00072: make_sock: could not bind to
address [::]:9011
(98)Address already in use: AH00072: make_sock: could not bind to
address 0.0.0.0:9011
no listening sockets available, shutting down
AH00015: Unable to open logs
After I killed the process using:
kill -9 10989
Is there a way to restore this process?
Thanks for any help in advance!

pm2 reload ecosystem.config.js causing many restarts on application

I am experiencing problems reloading the application using the ecosystem.config.js file. When the application is started for the first time, it starts correctly, but when I refresh/reload the application using the ecosystem.config.js file, the application restarts several times causing an error.
My SO is Ubuntu Xenial, PM2 version is 3.2.2 and Node v10.13.0. The application uses the latest version from Express module (4.16.4).
If I reload the application with "pm2 reload app_name", this problem doesn't occur.
The ecosystem.config.js content:
module.exports = {
apps: [{
script: "./index.js",
instances: "max",
exec_mode: "cluster",
kill_timeout: "2000",
env: {
NODE_ENV: "development",
},
env_production: {
NODE_ENV: "production",
}
}]
}
When I run the first time:
$ pm2 reload ecosystem.config.js
[PM2][WARN] Applications index not running, starting...
[PM2] App [index] launched (2 instances)
node#ubuntu:/data/$ pm2 logs
[TAILING] Tailing last 15 lines for [all] processes (change the value with >--lines option)
/home/node/.pm2/pm2.log last 15 lines:
PM2 | 2018-11-23T13:14:30: PM2 log: App [index:0] starting in -cluster >mode-
PM2 | 2018-11-23T13:14:31: PM2 log: App [index:0] online
PM2 | 2018-11-23T13:14:31: PM2 log: App [index:1] starting in -cluster >mode-
PM2 | 2018-11-23T13:14:31: PM2 log: App [index:1] online
When I reload the application by name (ex: pm2 reload app_name), the application contiue runnig, but I see some timeouts to kill process:
PM2 | 2018-11-23T14:01:02: PM2 log: pid=11296 msg=failed to kill - retrying in 100ms
PM2 | 2018-11-23T14:01:02: PM2 log: Process with pid 11289 still alive after 6000ms, sending it SIGKILL now...
PM2 | 2018-11-23T14:01:02: PM2 log: pid=11296 msg=failed to kill - retrying in 100ms
PM2 | 2018-11-23T14:01:02: PM2 log: Process with pid 11296 still alive after 6000ms, sending it SIGKILL now...
PM2 | 2018-11-23T14:01:02: PM2 log: App name:index id:_old_0 disconnected
PM2 | 2018-11-23T14:01:02: PM2 log: App [index:_old_0] exited with code [0] via signal [SIGKILL]
PM2 | 2018-11-23T14:01:02: PM2 log: App name:index id:_old_1 disconnected
PM2 | 2018-11-23T14:01:02: PM2 log: App [index:_old_1] exited with code [0] via signal [SIGKILL]
PM2 | 2018-11-23T14:01:02: PM2 log: pid=11289 msg=process killed
PM2 | 2018-11-23T14:01:02: PM2 log: pid=11296 msg=process killed
But, even though timeouts occur the application is running.
When I execute "pm2 reload ecosystem.config.js", the PM2 restart the application several times and one instance fail:
0|index | at Module.load (internal/modules/cjs/loader.js:598:32)
0|index | at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
0|index | at Function.Module._load (internal/modules/cjs/loader.js:529:3)
0|index | at Object. (/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js:48:21)
0|index | Error: listen EADDRINUSE :::3001
I believe the problem is related to some timeout to properly terminate the http connection of the Express module, but I'm still investigating this.
It has been fixed on the lastest PM2 version, please update:
npm install pm2#latest -g
pm2 update
Make sure you pm2 delete all and then start back your application again, it will work then when doing reload or restart

Port specified when running node is undefined

The port is specified when i ran the node project says undefined.
> sf-chain#1.0.0 dev E:\System\dev\node\sf-chain
> nodemon ./app "HTTP_PORT=3002" "P2P_PORT=5002" "PEERS=ws://localhost:5001"
[nodemon] 1.18.3
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node ./app HTTP_PORT=3002 P2P_PORT=5002 PEERS=ws://localhost:5001`
process.env.HTTP_PORT :: undefined
HTTP_PORT :: 3001
Listening for peer-to-peer connections on: 5001
events.js:160
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::3001
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at Server._listen2 (net.js:1259:14)
at listen (net.js:1295:10)
at Server.listen (net.js:1391:5)
at EventEmitter.listen (E:\System\dev\node\sf-chain\node_modules\express\lib\application.js:618:24)
at Object.<anonymous> (E:\System\dev\node\sf-chain\app\index.js:28:5)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
[nodemon] app crashed - waiting for file changes before starting...
I ran the first instance using
npm run dev
const HTTP_PORT = process.env.HTTP_PORT || 3001;
The application starts successfully running on port 3001 since i didn't specify HTTP_PORT at the run command.
But when trying to run another instance by specifying HTTP_PORT using the below command
npm run dev HTTP_PORT=3002 P2P_PORT=5002 PEERS=ws://localhost:5001
I get this error.
Error: listen EADDRINUSE :::3001
Which means the HTTP_PORT specified at run time is seen as undefined that's why it's trying to using the 3001 port for the first instance.
Error: listen EADDRINUSE
- error comes when somthing is already running/listen on that port
Its because sometime instance of same nodejs acquire port and didnt kill/exit the process properly,
if you have Ubuntu check first which process is using port by
lsof -i :3001 // Port no.
then output will be some thing like this.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 2496 nasiruddin 13u IPv6 37696 0t0 TCP *:3001 (LISTEN)
kill using PID
kill 2496
then start again

Failed to start httpd server: Address already in use

Surely I know that same question is already posted here. However, when I searched it, the status is different from mine and I cannot understand the answers. Therefore I post my problem here. Sorry for duplicating issues.
My homepage suddenly doesn't work and I found out that it failed to start httpd service. Following image is the result when I command 'sudo service httpd start'
Starting httpd: (98)Address already in use: AH00072: make_sock: could
not bind to address [::]:80 (98)Address already in use: AH00072:
make_sock: could not bind to address 0.0.0.0:80 no listening sockets
available, shutting down AH00015: Unable to open logs
[FAILED]
restart doesn't work also.
$ sudo service httpd restart
Stopping httpd: [FAILED]
Starting httpd: (98)Address already in use: AH00072: make_sock: could not bind
to address [::]:80 (98)Address already in use: AH00072: make_sock:
could not bind to address 0.0.0.0:80 no listening sockets available,
shutting down AH00015: Unable to open logs
[FAILED]
What should I do to restart httpd service and revive my homepage?
Error 98 usually occurs when some webserver is using the port, here 80, or
The clean release port/address was not done.
If port is being used by other webserver, shutdown the server. You can find out which service is using port 80 by
netstat -pan |grep 80
and then shutdown the service.
If the port was not released upon unclean shutdown of server, then
sudo service networking restart
to release address/port combination from bind. This usually fixes error 98 for me.
I have the same problem. So i looked to netstat:
sudo netstat -tulpn | grep :80
and received:
tcp6 0 0 :::80 :::* LISTEN 7836/docker-proxy
after killing process:
sudo kill 7836
Files defined inside conf.d would have Listen port as 80 along with repetitive declaration of Listen port in httpd.conf which can cause this issue.
Seems port 80 is used by some other process, it can be checked by "netstat -anp|grep :80" Or assign a new available port to the Listen directive in httpd.conf and restart httpd.
Your httpd server is already started. Try restarting the service instead of starting it again:
sudo service httpd restart

node server is starting automatically and can't be killed

Environment
Windows 10 Pro
PATH setting:
C:\Program Files (x86)\nodejs\ (v0.10.13)
C:\Program Files\nodejs (v6.2.2)
node version global: v6.2.2
npm version : 3.9.5
Description
I installed node.js, and right after installation I got problem because nodejs starting background process taking port 8080 which must not be taken.
running command:
>netstat -ano | find "8080"
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 4428
running command:
>taskkill /IM "node.exe" /T /F
SUCCESS: The process with PID 6140 (child process of PID 4428) has been terminated.
SUCCESS: The process with PID 2916 (child process of PID 2776) has been terminated.
SUCCESS: The process with PID 10888 (child process of PID 2776) has been terminated.
SUCCESS: The process with PID 4428 (child process of PID 2556) has been terminated.
SUCCESS: The process with PID 2776 (child process of PID 2560) has been terminated.
>netstat -ano | find "8080"
But after some time server is started again:
>netstat -ano | find "8080"
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 11052
Looked up startup applications, services and scheduled tasks, found nothing containing node or npm.
Also found no info on this event in application logs of mmc console.
What part of windows system can cause startup of node server?
How can I change this default port for node server?
Also noticed that if i'll start some other process and bind it to 8080 right after killing node.exe processes, then node trying to: [start new process and connect to 8080]----{fail}---->[retry attempt].
Task manager displays 2 node.exe processes on port 8000 and 8080. Get request on those ports result in "Cannot get /". All processes of node pointing to C:\Program Files (x86)\nodejs\ (v0.10.13).
SOLVED
Don't know why exactly, but it seems that version v0.10.13 of node which (was installed along with aptana studio 3) has some sort of service, which wasn't easily visible in service list and which was causing the trouble. Removal of this old version of node removed server instances from processes.

Resources