Search code examples
node.jscentosmosquittomqtt.js

Getting Erorr ECONNRESET intermittently with mosquitto and node.js


I am getting an intermittent error at node.js end intermittently while subscribing the topic from MQTT. I have configured MQTT log files and found the below error Unable to accept new connection, system socket count has been exceeded. Try increasing "ulimit -n" or equivalent.

While I am encounter the above message at mqtt logile, I am getting the error ECONNRESET at node.js end at the same time.

I have checked the ulimit at the server end and gives me the below details

 ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 256380
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 62987
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

My Linux version is as below

Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-1062.12.1.vz7.131.10
      Architecture: x86-64

Is the problem is related to uilmit? Do I need to increase the value of ulimit at server level? How to fix the issue for ECONRESET at node.js


Solution

  • You need to increase the open files count on the broker.

    You can do it for the running process with the prlimit command, but you should do it for the user running mosquitto so it's persistent across restarts. You can do this by editing the /etc/security/limits.conf file. You will need to log out and back in for it to take effect for a normal user and probably restart the service for a daemon user.