使用 mosquitto 和 node.js 间歇性地获取错误 ECONNRESET

Getting Erorr ECONNRESET intermittently with mosquitto and node.js

我在从 MQTT 订阅主题时间歇性地在 node.js 结束时遇到间歇性错误。 我已经配置了 MQTT 日志文件并发现了以下错误 Unable to accept new connection, system socket count has been exceeded. Try increasing "ulimit -n" or equivalent.

虽然我在 mqtt logile 遇到上述消息,但同时在 node.js 结束时收到错误 ECONNRESET。

我检查了服务器端的 ulimit 并提供了以下详细信息

 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

我的Linux版本如下

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

问题与uilmit有关吗?我是否需要在服务器级别增加 ulimit 的值? 如何在 node.js

解决 ECONRESET 问题

您需要增加 open files 经纪人的数量。

您可以使用 prlimit 命令为 运行 进程执行此操作,但您应该为用户 运行 mosquitto 执行此操作,以便它在重新启动后保持不变。您可以通过编辑 /etc/security/limits.conf 文件来完成此操作。您将需要注销并重新登录才能对普通用户生效,并且可能需要为守护进程用户重新启动服务。