node.js requires to many TCP sockets

177 views
Skip to first unread message

Spab Rice

unread,
Mar 17, 2015, 9:42:13 AM3/17/15
to nod...@googlegroups.com
Hello,

I'm new to node.js.
My script creates/open too many TCP Sockets which I don't have any plan how to prevent this?

Please see the StackOverflow link to have full details of my problem.
http://stackoverflow.com/questions/29077409/node-js-requires-to-many-tcp-sockets

Does anyone have some tips for me? Is my code bad?
Any help is really appreciated.

// ravi

unread,
Mar 17, 2015, 1:06:38 PM3/17/15
to nod...@googlegroups.com
Looks like you are using socket.io? You may wish to listen for close/end events to gracefully shutdown client communications — check the socket.io docs for the specific events (I haven’t used socket.io in a while). Does your service have a lot of clients?

—ravi


Zach Rollyson

unread,
Mar 17, 2015, 1:06:42 PM3/17/15
to nod...@googlegroups.com
Could you post a little more info: what version of node are you using & what is the exact error message?  Also, it probably doesn't matter but Linux 8.0 doesn't say a whole lot about your environment as compared to something like the output of cat /etc/*-release

Matt

unread,
Mar 17, 2015, 2:31:29 PM3/17/15
to nod...@googlegroups.com
Looks like an EMFILE error. You need to set ulimit -n higher.

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/085f37c4-c49c-40f8-8aa5-85abcd0bb10a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Spab Rice

unread,
Mar 19, 2015, 10:59:49 AM3/19/15
to nod...@googlegroups.com
I might also notice that I'm using 'forever' in order to keep the node Server up and running continuously

Spab Rice

unread,
Mar 19, 2015, 10:59:57 AM3/19/15
to nod...@googlegroups.com
Thanks for your feedback.

Yes I'm using socket.io.  I will have a look on this, but I think the sockets should close automatically if client leave the app, doesn't it?
Yes the service has many clients and it's growing.
At the moment the app can run 5-6 days without problems, and then once the TCP sockets are exhausted the whole server crashes.
As I said, I currently can prevent this by stopping and restarting the node process.


Spab Rice

unread,
Mar 19, 2015, 11:00:01 AM3/19/15
to nod...@googlegroups.com
Thanks for your feedback.
my node version is 0.10.32. I'm also using socket.io (v. 1.3.5) and express (v 4.12.3)

I don't get an error message. The server crashed and wasn't available on first time. I needed to reboot it.  At the moment I can prevent the crashing by just stop the node process and restart it. This way it resets/deletes all TCP sockets created but there must be another solution.

// ravi

unread,
Mar 19, 2015, 11:11:12 AM3/19/15
to nod...@googlegroups.com
On Mar 19, 2015, at 6:10 AM, Spab Rice <spab...@gmail.com> wrote:
>
> Yes I'm using socket.io. I will have a look on this, but I think the sockets should close automatically if client leave the app, doesn't it?
> Yes the service has many clients and it's growing.
> At the moment the app can run 5-6 days without problems, and then once the TCP sockets are exhausted the whole server crashes.


At one of these points where the app has been running for say 3 or 4 days, can you run ‘netstat -na’ and share the output? Please reduce the output of the command to only those ports that are relevant for your app (you can do that by using netstat options, or using -p and grep'ing for your process PID, or by the port). You may also wish to mask IP addresses if you have privacy/security concerns.

—ravi

Spab Rice

unread,
Mar 24, 2015, 9:20:17 AM3/24/15
to nod...@googlegroups.com
I did a 'netstat -na’

I have a lot of this
...
tcp        
0      0 85.222.94.102:8080      82.235.167.251:39853    VERBUNDEN  
tcp        
0      0 85.222.94.102:8080      63.235.83.197:54544     VERBUNDEN  
tcp        
0      0 85.222.94.102:8080      66.77.124.166:1138      VERBUNDEN  
tcp        
0      0 85.222.94.102:8080      71.238.83.197:54441     VERBUNDEN  
tcp        
0      0 85.222.94.102:8080      55.16.224.251:57015     VERBUNDEN  
tcp        
0      0 85.222.94.102:8080      63.238.83.194:54398     VERBUNDEN  
tcp        
0      0 85.222.94.102:8080      82.3.230.222:64944      VERBUNDEN
...
VERBUNDEN means 'connected'


and a lot of this
...
tcp6      
0      0 85.222.94.102:80        93.0.129.72:54926       TIME_WAIT  
tcp6      
0      0 85.222.94.102:80        55.88.48.11:52137       TIME_WAIT  
tcp6      
0      0 85.222.94.102:80        96.0.132.72:54959       TIME_WAIT  
tcp6      
0      0 85.222.94.102:80        82.4.231.233:56815      TIME_WAIT  
tcp6      
0      0 85.222.94.102:80        82.4.231.233:56810      TIME_WAIT  
tcp6      
0      0 85.222.94.102:80        82.4.231.233:56829      VERBUNDEN  
tcp6      
0      0 85.222.94.102:80        112.57.267.29:50781     TIME_WAIT
...


and also a lot of this
...
unix  
3      [ ]         STREAM     VERBUNDEN     3177882023
unix  
3      [ ]         STREAM     VERBUNDEN     3179982022
unix  
3      [ ]         STREAM     VERBUNDEN     3179785519
unix  
3      [ ]         STREAM     VERBUNDEN     3179747018

...

Hope this helps
Reply all
Reply to author
Forward
0 new messages