Erlang Elixir-Phoenix-函数:erl_posix_msg.message/1未定义
我有两台服务器运行一个非常简单的Phoenix framework API,大约每周,其中一台服务器开始抛出502个错误Erlang Elixir-Phoenix-函数:erl_posix_msg.message/1未定义,erlang,elixir,phoenix-framework,gen-server,beam,Erlang,Elixir,Phoenix Framework,Gen Server,Beam,我有两台服务器运行一个非常简单的Phoenix framework API,大约每周,其中一台服务器开始抛出502个错误 15:35:08.260 [error] 'File operation error: emfile. Target: /usr/lib/erlang/lib/stdlib-3.2/ebin/erl_posix_msg.beam. Function: get_file. Process: code_server.' 15:35:08.323 [error] 'File op
15:35:08.260 [error] 'File operation error: emfile. Target: /usr/lib/erlang/lib/stdlib-3.2/ebin/erl_posix_msg.beam. Function: get_file. Process: code_server.'
15:35:08.323 [error] 'File operation error: emfile. Target: erl_posix_msg.beam. Function: get_file. Process: code_server.'
15:35:08.324 [error] GenServer #PID<0.6569.17> terminating
** (UndefinedFunctionError) function :erl_posix_msg.message/1 is undefined (module :erl_posix_msg is not available)
(stdlib) :erl_posix_msg.message(:emfile)
(redix) lib/redix.ex:393: Redix.format_error/1
(redix) lib/redix/connection.ex:108: Redix.Connection.connect/2
(connection) lib/connection.ex:622: Connection.enter_connect/5
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: nil
State: %Redix.Connection{backoff_current: nil, opts: [socket_opts: [], sync_connect: false, backoff_initial: 500, backoff_max: 30000, log: [disconnection: :error, failed_connection: :error, reconnection: :info], exit_on_disconnection: false, host: "redis.host.not", port: 6379], receiver: nil, shared_state: nil, socket: nil}
15:35:08.324 [error] Ranch protocol #PID<0.6568.17> (:cowboy_protocol) of listener Auth.Endpoint.HTTP terminated
** (exit) an exception was raised:
** (UndefinedFunctionError) function :erl_posix_msg.message/1 is undefined (module :erl_posix_msg is not available)
(stdlib) :erl_posix_msg.message(:emfile)
(redix) lib/redix.ex:393: Redix.format_error/1
(redix) lib/redix/connection.ex:108: Redix.Connection.connect/2
(connection) lib/connection.ex:622: Connection.enter_connect/5
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
15:35:08.260[错误]'文件操作错误:emfile。目标:/usr/lib/erlang/lib/stdlib-3.2/ebin/erl_posix_msg.beam。功能:获取文件。进程:代码\服务器。'
15:35:08.323[错误]'文件操作错误:emfile。目标:erl_posix_msg.beam。功能:获取文件。进程:代码\服务器。'
15:35:08.324[错误]发电机服务器#PID终止
**(UndefinedFunctionError)函数:erl_posix_msg.message/1未定义(模块:erl_posix_msg不可用)
(stdlib):erl_posix_msg.message(:emfile)
(redix)lib/redix.ex:393:redix.format_错误/1
(redix)lib/redix/connection.ex:108:redix.connection.connect/2
(connection)lib/connection.ex:622:connection.enter_connect/5
(stdlib)proc_lib.erl:247::proc_lib.init_p_do_apply/3
最后信息:无
状态:%Redix.Connection{backoff\u current:nil,opts:[socket\u opts:[],sync\u connect:false,backoff\u initial:500,backoff\u max:30000,log:[disconnection::error,failed\u Connection::error,reconnection::info],exit\u on\u disconnection:false,host:“redis.host.not”,端口:6379],接收方:nil,共享\u状态:nil,socket:nil}
15:35:08.324[错误]侦听器Auth.Endpoint.HTTP的Ranch协议#PID(:cowboy_协议)已终止
**(退出)引发了一个异常:
**(UndefinedFunctionError)函数:erl_posix_msg.message/1未定义(模块:erl_posix_msg不可用)
(stdlib):erl_posix_msg.message(:emfile)
(redix)lib/redix.ex:393:redix.format_错误/1
(redix)lib/redix/connection.ex:108:redix.connection.connect/2
(connection)lib/connection.ex:622:connection.enter_connect/5
(stdlib)proc_lib.erl:247::proc_lib.init_p_do_apply/3
如果我重新启动phoenix服务器,砰的一声,一切又开始工作了。显然,这不是一个可扩展的解决方案,但我正在努力诊断到底发生了什么
任何帮助都是甜蜜的
感谢阅读本模块,您可以看到它只是针对“打开的文件太多”编写的代码。
emfile
=打开的文件太多
()。很有可能是文件描述符泄漏了,一周后它达到了打开文件的数量限制。很好,你没有错。所以我运行:ulimit-a
,对于这个。。。打开文件(-n)1024。。。然后我运行:lsof-I-n-P | wc-l`来打开所有的连接(99%到Redis)。结果是1028。这就是问题所在。所以下一个问题是为什么Elixir/Phoenix没有杀死文件描述符。你能在创建Redix实例的地方发布代码吗?可能是因为某些原因,它们没有被关闭,或者你创建了太多的实例。所以我使用了一个非常简单的模块,看起来是这样的:get_conn方法在每个控制器之前由一个插件运行,kill_conn方法由我们的响应模块运行,我使用日志来保证连接被终止肯定正在运行。一周后,您只有约1000个额外连接。可能在某些边缘情况下,kill\u conn
不存在?