https not working in Linux with node/express/webpack - node.js

I have a nodejs application, I am able to configure https and run it locally on my windows machin, but when I do the same run on my Linux machin it fails with below error.
EADDRINUSE: address already in use 0.0.0.0:3006
events.js:282
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use 0.0.0.0:3006
at Server.setupListenHandle [as _listen2] (net.js:1308:16)
at listenInCluster (net.js:1356:12)
at doListen (net.js:1495:7)
at processTicksAndRejections (internal/process/task_queues.js:85:21)
Emitted 'error' event on Server instance at:
at emitErrorNT (net.js:1335:8)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 'EADDRINUSE',
errno: -98,
syscall: 'listen',
address: '0.0.0.0',
port: 3006
}
As suggested by other I tried 'netstat -plnt' but the port 3006 is nowhere used, so nothing to kill.
Not sure if this is code issue or OS issue.
[Update] chnaged the port to 3006
netstat -plnt
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN -
tcp6 0 0 :::111 :::* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -

Try using fuser 1223/tcp to get the process and
fuser -k 1223/tcp to kill the process running on the specific port

Related

node running server throw Error regarding already runinng port

Emitted 'error' event on Server instance at:
at emitErrorNT (net.js:1340:8)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 'EADDRINUSE',
errno: 'EADDRINUSE',
syscall: 'listen',
address: '::',
port: 8082
}
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::8082
First findout your processID for your running process
lsof -i:1234(your port ID)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Google 55523 ssurisettii 42u IPv6 0x53ab9cb514809733 0t0 TCP localhost:53991->localhost:us-cli (CLOSE_WAIT)
Google 55523 ssurisettii 45u IPv6 0x53ab9cb51480d473 0t0 TCP localhost:53989->localhost:us-cli (CLOSE_WAIT)
Google 55523 ssurisettii 46u IPv6 0x53ab9cb514809d53 0t0 TCP localhost:53990->localhost:us-cli (CLOSE_WAIT)
this ways shows,
Now you kill the your related processID
suppose your port id contains processID 1234
then **** kill -9 1234 ***

Passenger, Plesk and Node.js: address already in use

My question is about getting Phusion Passenger and Plesk Onyx 17.5.3 to work together nicely. I have a new server running Ubuntu 16.04.
I am following the official Phusion Passenger tutorial on deploying a Node.js app, and I have followed it successfully to the point where I need to tell Passenger to listen on port 80.
Here are my steps:
With my registrar, I set up a DNS entry for the subdomain pass.domain.com
In the Plesk interface, I define the new subdomain
If I visit http://pass.domain.com in my browser, I get the default Plesk web page.
I follow the "Phusion Passenger: Node.js tutorial" until I reach this command:
sudo passenger start --port 80 --user someusername --environment production --daemonize
Note: I am using a valid custom user name in the place of `someusername'.
I get this error:
Could not start the Nginx engine:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
It appears that Plesk is already serving the default web page at this address, so Phusion Passenger cannot access it. What files do I need to add or edit to get Plesk to release the address so that Passenger can use it?
EDIT 4: I have found this question which describes similar symptoms. However the OP is using Meteor Up and I am using Passenger. His solution was to get Meteor Up to tell Node.js to run on port 3001, and get nginx to listen on port 80 and proxy requests to port 3001. I had understood that Phusion Passenger already does something similar under the hood.
Is there a way to modify the passenger start command to clarify this?
OLDER EDITS
EDIT 1: In response to #TarunLalwali, here is the output of sudo netstat -plnat on this server:
$ sudo netstat -plnat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:4190 0.0.0.0:* LISTEN 15234/dovecot
tcp 0 0 127.0.0.1:12768 0.0.0.0:* LISTEN 15654/psa-pc-remote
tcp 0 0 0.0.0.0:993 0.0.0.0:* LISTEN 15234/dovecot
tcp 0 0 0.0.0.0:995 0.0.0.0:* LISTEN 15234/dovecot
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 2293/mongod
tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 15234/dovecot
tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 15234/dovecot
tcp 0 0 127.0.0.1:783 0.0.0.0:* LISTEN 1315/.spamassassin
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 26659/nginx
tcp 0 0 0.0.0.0:8880 0.0.0.0:* LISTEN 23894/config
tcp 0 0 0.0.0.0:465 0.0.0.0:* LISTEN 2142/master
tcp 0 0 172.17.0.1:53 0.0.0.0:* LISTEN 17312/named
tcp 0 0 94.76.206.212:53 0.0.0.0:* LISTEN 17312/named
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 17312/named
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1413/sshd
tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 12563/passenger-sta
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 17312/named
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 2142/master
tcp 0 0 94.76.206.212:443 0.0.0.0:* LISTEN 26659/nginx
tcp 0 0 0.0.0.0:8443 0.0.0.0:* LISTEN 23894/config
tcp 0 0 94.76.206.212:993 92.130.47.95:49994 ESTABLISHED 15322/imap-login
tcp 0 0 127.0.0.1:51168 127.0.0.1:12768 TIME_WAIT -
tcp 0 0 94.76.206.212:25 200.188.141.75:51400 TIME_WAIT -
tcp 0 188 94.76.206.212:22 92.130.47.95:34414 ESTABLISHED 4035/sshd: blacksla
tcp6 0 0 :::4190 :::* LISTEN 15234/dovecot
tcp6 0 0 :::993 :::* LISTEN 15234/dovecot
tcp6 0 0 :::995 :::* LISTEN 15234/dovecot
tcp6 0 0 :::7080 :::* LISTEN 26432/apache2
tcp6 0 0 :::7081 :::* LISTEN 26432/apache2
tcp6 0 0 127.0.0.1:3306 :::* LISTEN 10040/mysqld
tcp6 0 0 :::106 :::* LISTEN 1532/xinetd
tcp6 0 0 :::110 :::* LISTEN 15234/dovecot
tcp6 0 0 :::143 :::* LISTEN 15234/dovecot
tcp6 0 0 ::1:783 :::* LISTEN 1315/.spamassassin
tcp6 0 0 2a02:af8:1:900::3860:80 :::* LISTEN 26659/nginx
tcp6 0 0 :::8880 :::* LISTEN 23894/config
tcp6 0 0 :::465 :::* LISTEN 2142/master
tcp6 0 0 :::53 :::* LISTEN 17312/named
tcp6 0 0 :::21 :::* LISTEN 1532/xinetd
tcp6 0 0 :::22 :::* LISTEN 1413/sshd
tcp6 0 0 :::25 :::* LISTEN 2142/master
tcp6 0 0 2a02:af8:1:900::386:443 :::* LISTEN 26659/nginx
tcp6 0 0 :::8443 :::* LISTEN 23894/config
Note: I have already asked about this issue on the Plesk forum, but it has received no response. I am hoping that asking the Phusion Passenger community here will be more productive. Once I have a working solution, I will post a link from the Plesk forum to the answer here.
Thanks in advance for your insights,
James
EDIT 2: Following #TarunLalwali's advice, I tried stopping nginx, but this produced an unknown error:
$ sudo nginx -s stop
$ sudo passenger start --port 80 --user node --environment production --daemonize
Could not start the Nginx engine:
nginx: [alert] Unable to start the Phusion Passenger watchdog because it encountered the following error during startup: Unable to start the Passenger core: it seems to have crashed during startup for an unknown reason, with exit code 1 (-1: Unknown error)
EDIT 3: Attempting to disable nginx server-wide before invoking Passenger:
$ sudo systemctl disable nginx
Synchronizing state of nginx.service with SysV init with /lib/systemd/systemd-sysv-install...
Executing /lib/systemd/systemd-sysv-install disable nginx
insserv: warning: current start runlevel(s) (empty) of script `nginx' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `nginx' overrides LSB defaults (0 1 6).
$ systemctl status nginx
* nginx.service - Startup script for nginx service
Loaded: loaded (/lib/systemd/system/nginx.service; disabled; vendor preset: enabled)
Active: inactive (dead)
$ sudo passenger start --port 80 --user node --environment production --daemonize
Could not start the Nginx engine:
nginx: [alert] Unable to start the Phusion Passenger watchdog because it encountered the following error during startup: Unable to start the Passenger core: it seems to have crashed during startup for an unknown reason, with exit code 1 (-1: Unknown error)
You mention that you need the system Nginx (at port 80) to run other subdomains on the server.
Passenger Standalone can coexist peacefully with a system Nginx using two steps:
Run it on a non-conflicting port, for example the default 3000:
sudo passenger start --port 3000 --user someusername --environment production --daemonize
For the domain that you want Passenger to server, tell the system Nginx to proxy to Passenger.
proxy_pass http://localhost:3000;
Remember to reload/restart Nginx to activate the config.
How to do step 2 exactly in Plesk is a question best asked on the Plesk forum, but from the Passenger point of view this setup should work.

Error: listen EADDRINUSE :::443 error when trying to start nodejs server

I am trying to create a nodejs application that uses SSL. I have the cert, domain, and nodejs configured and working, but I'm having a problem sometimes when I stop my node server using Ctrl+C. I am getting the following error when trying to restart the node server:
Error: listen EADDRINUSE :::443
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at Server._listen2 (net.js:1237:14)
at listen (net.js:1273:10)
at Server.listen (net.js:1369:5)
at Object.<anonymous> (/var/www/html/server.js:212:47)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
Now I know this means that the port is in use, but I've tried several things to find the process that is using that port but I cant. A couple thing I've tried that are worth mentioning are netstat:
$ sudo netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1164/sshd
tcp6 0 0 :::22 :::* LISTEN 1164/sshd
udp 0 0 0.0.0.0:68 0.0.0.0:* 882/dhclient
and ps:
$ ps aux |grep node
ubuntu 7632 0.0 0.0 12944 988 pts/0 S+ 23:30 0:00 grep --color=auto node
but neither of them show me what is using port 443. I have pm2 to keep my node server in a running state, but it keeps saying errored and then I find the EADDRINUSE errors in the pm2 error log. I've been banging my head against the wall for hours. Can anyone assist me? Thanks!
I had this issue and the only command that revealed the process was
sudo lsof -iTCP -sTCP:LISTEN -P

All of a sudden -- tcp connect (localhost:5432): connection refused - :econnrefused

For a few months all has been ok, but now I have a lot of:
mix phoenix.server
[error] Postgrex.Protocol (#PID<0.302.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
[error] Postgrex.Protocol (#PID<0.303.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
on localhost.
But:
Postgresql is running
Its config is the same
The config of my phoenix/elixir application is the same too.
systemctl status postgresql shows everything is ok
nothing bad in the log
I can connect to Pg via Pg GUI tool
What's the matter?
$ netstat -tulnp
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp6 0 0 ::1:5432 :::* LISTEN -
udp 0 0 192.168.1.37:68 0.0.0.0:* -
udp 0 0 0.0.0.0:5353 0.0.0.0:* 25117/libpepflashpl
udp6 0 0 :::5353 :::* 25117/libpepflashpl

Express http only working with localhost but not with external ip http connection

Tried to avoid the listen IP only on the '127.0.0.1', so the listen port 8000 is also bind with the '0.0.0.0'. But external http clients still not able to get the http connection setup. Also tried tcpdump, the client SYN can reach to the node server, but not any response from the node.js http server... this caused the issue. Really appreciate your assistance!
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 1650/node
tcp 0 0 127.0.0.1:56064 127.0.0.1:27017 ESTABLISHED 1650/node
tcp 0 0 127.0.0.1:56062 127.0.0.1:27017 ESTABLISHED 1650/node
tcp 0 0 127.0.0.1:56065 127.0.0.1:27017 ESTABLISHED 1650/node
tcp 0 0 127.0.0.1:56063 127.0.0.1:27017 ESTABLISHED 1650/node
tcp 0 0 127.0.0.1:56061 127.0.0.1:27017 ESTABLISHED 1650/node

Resources