1

I have deployed MEAN stack on an EC2 ubuntu machine. I have written a crawler script that creates a child process for every URL I feed it and crawls and returns back the data to the parent. I don't really have a clue of where the following error occurs.

Error: listen EADDRINUSE at exports._errnoException (util.js:746:11) at Agent.Server._listen2 (net.js:1129:14) at listen (net.js:1155:10) at Agent.Server.listen (net.js:1240:5) at Object.start (_debugger_agent.js:20:9) at startup (node.js:86:9) at node.js:814:3

Each child process returns an object which I print in the console and in between which I get a lot of above error. My script is very large and I don't know where this error occurs and so I am unable to post any code.

The server is running fine on port 8000. netstat -tpln shows only mongodb and ssh process occupying ports 27017 and 22 respectively. I have also tried changing the server ports but the same problem persists.

How do I find due to which port this error occurs? How do I find which line of code triggers this error?

Any input would be really appreciated. Thanks in advance.

bala
  • 83
  • 2
  • 7
  • 2
    Do you have multiple node.js applications running that are listening on the same port? – Kevin B Mar 25 '15 at 14:32
  • Thanks for the immediate reply. I do not have any other node.js applications running in the system – bala Mar 25 '15 at 14:38
  • When you list the processes on the server, do you see node.js running when you have the app not running? (ensuring there is no other version of it running on a disconnected session etc.) – Kevin B Mar 25 '15 at 14:40
  • Here's a related question: http://stackoverflow.com/questions/9898372/nodejs-error-listen-eaddrinuse?rq=1 – Kevin B Mar 25 '15 at 14:44
  • I used ps aux | grep node to check and found that there is no other node processes running. – bala Mar 25 '15 at 14:47
  • 1
    Then your node application itself must be trying to listen to the same port twice. – Kevin B Mar 25 '15 at 14:51
  • My script will spawn a number of child processes. Is there a chance that the child processes trying to bind the same port as the parent process and hence I get this error? – bala Mar 25 '15 at 14:53
  • That's definitely a possibility. Though, I don't know how to track that other than adding more error handling within your code. – Kevin B Mar 25 '15 at 14:54
  • But the same code is working perfectly in my localhost. Trouble started when I moved the code to ec2 machine. – bala Mar 25 '15 at 15:00
  • It shouldn't make any difference, unless you have something else on the server listening on the port you are using. nginx maybe? – Kevin B Mar 25 '15 at 15:01
  • `sudo fuser 80/tcp` replace `80` with the port your process is trying to use. Repeat with all the ports that your process uses. – Kevin B Mar 25 '15 at 15:03
  • The problem must be due to some environment configuration because when I launched a new ec2 bitnami instance and deployed my application, IT WORKS LIKE CHARM :-) Thank you @KevinB – bala Mar 26 '15 at 08:26
  • This happened to me, in my case the problem was caused by the other command prompt running the same port. I closed the other one and it solved it. – CENT1PEDE May 18 '15 at 02:05
  • See a similar issue at http://stackoverflow.com/questions/8553957/how-to-release-localhost-from-error-listen-eaddrinuse/31072560#31072560 – Manohar Reddy Poreddy Jun 26 '15 at 11:57

0 Answers0