Node error EADDRINUSE but port is not used - javascript

Hello I have strange problem, Node keep throwing an error:
Error: listen EADDRINUSE: address already in use 0.0.0.0:44604
but this port is free. I have used several linux commands and also npx kill-port.
I know how to list of node process and how to find specific pid on linux. Im sure this port is free. Im very confused rn.
Also cleaned .js file to very basic node server without express and other libs. Still got the same error.
Also im using pm2 with few node apps and this problem with ports occurs on random app with random ports. But in this case i cannot use other port then 44604.
Maybe anyone faced the same issue and can help me?

Related

React Native -- cannot start because HTTP server already being used by another WebSocket server

I'm running npx react-native start/npx react-native run-android, and everything builds fine; however, the app cannot start a server properly. This is the error I'm getting:
Error: The HTTP/S server is already being used by another WebSocket server
at new WebSocketServer (.../node_modules/ws/lib/websocket-server.js:83:15)
at Object.attachToServer (.../node_modules/react-native/node_modules/#react-native-community/cli/build/commands/server/messageSocket.js:93:15)
at Object.runServer [as func] (.../node_modules/react-native/node_modules/#react-native-community/cli/build/commands/server/runServer.js:127:37)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Command.handleAction (.../#react-native-community/cli/build/index.js:164:9)
I've tried killing all react-native related processes, and even if I reboot the system, this error still persists. Any ideas on what might be causing this?
It looks to me like your processTicksAndRejections() method is trying to set up its own WebSocketServer instance to do its work, rather than using one that's already set up. Your error message means that you
already have an http/s server going
already have a websocket server set up on it
you're trying to set up another websocket server on that existing http/s server.
If you were trying to run two server processes on the same port, a different error message would show up.
I ended up solving this problem by removing the dependency #react-native-community/cli-platform-android altogether, but I'm not completely satisfied with the solution because I have to run npx react-native start and npx react-native run-android separately.

WebSockets working on localhost, but do not work on remote Ubuntu host

I have two applications - browser based client and NodeJS based server that are both communicating using WebSockets (I'm using ColyseusJS library). Problem is, that everything works fine while I'm testing them on localhost but when I deploy the application to my Ubuntu VPS server it stops working.
The message I receive in the browser while trying to connect is:
WebSocket connection to 'ws://X.X.X.X:8001/?colyseusid=' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET
So it reaches the server (because when server is disabled the message is "Error in connection establishment: net::ERR_CONNECTION_REFUSED") but it looks like it fails on Upgrade connection operation.
What is strange is that I managed to make it work yesterday (don't know how exactly), but had so much mess on my VPS that I decided to revert machine to it's starting state. After that it stopped working (code is unchanged). Maybe there are some additional dependencies that I need to install in order to make it work on my Ubuntu Server?
I would really appreciate your help.
Have you tried to port forward the port to the ip address of the said VPS in your router config? And also check out the firewalls.

Node.js - Server crashes when started on startup, doesn't crash when manually started

I am running Node.js and Socket.io for online chat.
I have created a file in:
/etc/init/example.conf
it has two lines:
start on startup
exec forever start /var/www/example.com/html/server.js //location of server file.
Whenever I start file upload in chat application, it crashes but instantly restarts.
Whenever I kill node process though, and start it manually - it works fine.
I also can't get any logs or anything from terminal as when it's auto started - it doesn't print me anything to terminal.
I am still new to Node.js and Linux in general.
Node.js is running on Express + Jade.
How do I determine specific cause?
I managed to solve my problem, after a bit of searching around I found out about tail command.
My issue was a bit harder to trace because Node.js was a process started by autostart so when I launched terminal and connected to server, process was just running in background basically and I wouldn't get any output (including exception messages).
Anyway, solution that worked for me was:
I typed
ps aux | grep node //to find PID of node process
then I went to following directory
cd /proc/[pid of running node service]/fd
In fd directory there are few objects you can get output from but if you want to attach and listen to servers output including uncaught exceptions, you need 1.
So:
tail -f 1
that way I was able to cause website to crash and see the output.

Socket.io on Heroku

I have a slight problem with use of Node.js and socket.io on Heroku. It works fine locally but as soon as I push it to Heroku and go on the website it gives me the application error page. Looking at the logs there is no explicit error but I have a feeling what it might be. When I run it locally, I use sudo node server to start the app. Just node server gives the same effect as that on heroku.
So basically, my question is: How do I get Heroku to run in sudo mode, or how can I remove the need to use sudo altogether?
Apologies as this is my first time using socket.io, so I am a bit unfamiliar with the workings of the library.
P.S. I am using Express 3.
I would check into the port you are using. On a normal ubuntu machine for example you may have to use sudo for low numbered ports (such as port 80). Besides that Heroku has a lot of load balancing going on, so the port you will use to connect to the service may not be the same as the port you tell the instance to listen on.
I would try using port 5000 as per this example from Heroku
Nodejs with sockets

Sails.js server not starting anymore

I am using Cloud 9 IDE to develop a simple CRUD application using Sails.js (node.js MVC framework). Up until today I had no trouble starting the Sails.js server.
Today, I've been trying to start the sails js server, but I keep getting this error:
warn: error raised: Error: listen EACCES
error: Server doesn't seem to be starting.
error: Perhaps something else is already running on port 8080?
I have checked my /config/local.js file and everything is just fine, as it should be. The port is set to process.env.PORT || 1337 so it shouldn't have any problems firing the server up.
I'm looking forward to your insight.
Thank you!
Open terminal and run this command:
$ lsof -i :8080
Output will show PID of process occupying port 8080: "httpd 1234 ....'
Then kill the process with this command
$ kill -9 1234
Sails will now run
Hmm-- looks like port 8080 isn't available. What happens if you try to switch the port? You may have another server running on that port. Or in some cases, hosts require the hostname to be set. I'd try switching the port first though.
The only real answer to this is: wait. C9 seems to kill servers in a weird way that causes Sails to jack up and blocks you from establishing another server. lsof -i doesn't show anything serving... but it still won't start. Seems to be an issue with Cloud 9 and Sails.js. If I serve a generic Node.js "Hello World" app on the same port, the issue doesn't occur. However, time, it seems, cures all. After awhile, Sails seems to snap out of it and starts serving again when lifted.
Incredibly weird.

Categories

Resources