Reputation: 5976
I am writing a game using websocket with ws module and I try to create some virtual websocket connections on my local computer to test it. However when I created more than 250 connections it gives an error:
throw er; // Unhandled 'error' event
^
Error: connect ECONNRESET 127.0.0.1:9999
at Object.exports._errnoException (util.js:1014:11)
at exports._exceptionWithHostPort (util.js:1037:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1138:14)
How to remove this error and get more connections for testing? I don't get the error when the connection number is in the range of 1 - 210. But over 210 sometimes I get this error and if the connection number is over 250 I always get this error. I am not sure what causes this error. Is it because my computer is not capable of handling so many local connections? I am using OSX Yosemite (10.10.5)
Upvotes: 1
Views: 1119
Reputation: 5976
Just found out this:
Increase TCP max connections on OSX
The reason is that the max open files number is limited in OSX Yosemite. I just need to change the max open files number and the max connection number.
I will put the commands from the above link here:
increate max open files
$ sysctl -a | grep files
kern.maxfiles = 12288
kern.maxfilesperproc = 10240
kern.maxfiles and kern.maxfilesperproc were small numbers, they need to be increased:
$ sudo sysctl -w kern.maxfiles=12288
$ sudo sysctl -w kern.maxfilesperproc=10240
after this, you can increase your account’s limit by ulimit -n:
$ ulimit -n 10240
increate max sockets
$ sysctl -a | grep somax
kern.ipc.somaxconn: 2048
It was a small number and need to be increased:
$ sudo sysctl -w kern.ipc.somaxconn=2048
Upvotes: 1