首页 > NodeJs的Redis客户端遇到failed - connect EMFILE错误

NodeJs的Redis客户端遇到failed - connect EMFILE错误

程序很简单,就是得到http请求后,用一个参数作为Key去blpop一个Redis实例,如果超时就关掉Redis客户端返回空字典的json,如果超时前得到了push的数据就返回数据,最后关掉Redis连接。
结果在Redis用info得到connected client数量才2000多的时候,Nodejs的redis客户端就开始连接出错,然后报

error:Error: Redis connection to xxx.xxx.xxx.xxx - connect EMFILE

events.js:72
throw er; // Unhandled 'error' event
^
Error: Redis connection to xxx.xxx.xxx.xxx:6379 failed - connect EMFILE
at RedisClient.on_error (/var/www/ncodoon/message/broker/node_modules/redis/index.js:185:24)
at Socket. (/var/www/ncodoon/message/broker/node_modules/redis/index.js:95:14)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:440:14
at process._tickCallback (node.js:415:13)

Redis所在服务器的ulimit -n 是102400,Nodejs所在服务器的也是这个数。离限制还早得很呢。所以叫改ulimit的可以退散了。


EMFILE 就是打开的文件过多的意思。

谁告诉你执行 ulimit 命令了?这个命令执行之后,只对其子进程有效。要对系统全局生效,需要配置 /etc/sysctl.conf 文件(并执行 sysctl -p 加载之)。当然使用 sysctl 命令直接修改也是可以的。

你可以通过阅读 /proc/<pid>/limits 文件来取得指定进程的资源限制设置,以确定你的设置是否已确实对该进程生效。

【热门文章】
【热门文章】