如何处理 erlang 中的 Rabbitmq 错误 shortstr_size?

How to handle Rabbitmq Error shortstr_size in erlang?

我正在使用 erlang 客户端库使用默认连接参数连接到本地 rabbitmq 服务器。我在 24 小时内遇到一次这个问题。我的 Erlang 应用程序无法处理此问题。 对于我的错误记录器,我收到了这些消息..

2017-08-06 12:45:03.883 [error] <0.3739.0>@rabbit_framing_amqp_0_9_1:shortstr_size:210 CRASH REPORT Process <0.3739.0> with 0 neighbours crashed with reason: bad argument in call to erlang:size([]) in rabbit_framing_amqp_0_9_1:shortstr_size/1 line 210
2017-08-06 12:45:03.883 [error] <0.3736.0> Supervisor {<0.3736.0>,amqp_channel_sup} had child writer started with rabbit_writer:start_link(#Port<0.2798>, 1, 131072, rabbit_framing_amqp_0_9_1, <0.3738.0>, {<<"client 127.0.0.1:56646 -> 127.0.0.1:5672">>,1}) at <0.3739.0> exit with reason badarg in context child_terminated
2017-08-06 12:45:03.900 [error] <0.3736.0> Supervisor {<0.3736.0>,amqp_channel_sup} had child writer started with rabbit_writer:start_link(#Port<0.2798>, 1, 131072, rabbit_framing_amqp_0_9_1, <0.3738.0>, {<<"client 127.0.0.1:56646 -> 127.0.0.1:5672">>,1}) at <0.3739.0> exit with reason reached_max_restart_intensity in context shutdown
2017-08-06 12:45:04.514 [error] <0.3754.0>@rabbit_framing_amqp_0_9_1:shortstr_size:210 CRASH REPORT Process <0.3754.0> with 0 neighbours crashed with reason: bad argument in call to erlang:size([]) in rabbit_framing_amqp_0_9_1:shortstr_size/1 line 210
2017-08-06 12:45:04.514 [error] <0.3751.0> Supervisor {<0.3751.0>,amqp_channel_sup} had child writer started with rabbit_writer:start_link(#Port<0.2819>, 1, 131072, rabbit_framing_amqp_0_9_1, <0.3753.0>, {<<"client 127.0.0.1:49559 -> 127.0.0.1:5672">>,1}) at <0.3754.0> exit with reason badarg in context child_terminated
2017-08-06 12:45:04.515 [error] <0.3751.0> Supervisor {<0.3751.0>,amqp_channel_sup} had child writer started with rabbit_writer:start_link(#Port<0.2819>, 1, 131072, rabbit_framing_amqp_0_9_1, <0.3753.0>, {<<"client 127.0.0.1:49559 -> 127.0.0.1:5672">>,1}) at <0.3754.0> exit with reason reached_max_restart_intensity in context shutdown
2017-08-06 12:45:04.846 [error] <0.3768.0>@rabbit_framing_amqp_0_9_1:shortstr_size:210 CRASH REPORT Process <0.3768.0> with 0 neighbours crashed with reason: bad argument in call to erlang:size([]) in rabbit_framing_amqp_0_9_1:shortstr_size/1 line 210
2017-08-06 12:45:04.846 [error] <0.3765.0> Supervisor {<0.3765.0>,amqp_channel_sup} had child writer started with rabbit_writer:start_link(#Port<0.2821>, 1, 131072, rabbit_framing_amqp_0_9_1, <0.3767.0>, {<<"client 127.0.0.1:60413 -> 127.0.0.1:5672">>,1}) at <0.3768.0> exit with reason badarg in context child_terminated
2017-08-06 12:45:04.846 [error] <0.3765.0> Supervisor {<0.3765.0>,amqp_channel_sup} had child writer started with rabbit_writer:start_link(#Port<0.2821>, 1, 131072, rabbit_framing_amqp_0_9_1, <0.3767.0>, {<<"client 127.0.0.1:60413 -> 127.0.0.1:5672">>,1}) at <0.3768.0> exit with reason reached_max_restart_intensity in context shutdown
2017-08-06 12:45:05.154 [error] <0.3782.0>@rabbit_framing_amqp_0_9_1:shortstr_size:210 CRASH REPORT Process <0.3782.0> with 0 neighbours crashed with reason: bad argument in call to erlang:size([]) in rabbit_framing_amqp_0_9_1:shortstr_size/1 line 210
2017-08-06 12:45:05.154 [error] <0.3779.0> Supervisor {<0.3779.0>,amqp_channel_sup} had child writer started with rabbit_writer:start_link(#Port<0.2823>, 1, 131072, rabbit_framing_amqp_0_9_1, <0.3781.0>, {<<"client 127.0.0.1:36301 -> 127.0.0.1:5672">>,1}) at <0.3782.0> exit with reason badarg in context child_terminated
2017-08-06 12:45:05.154 [error] <0.3779.0> Supervisor {<0.3779.0>,amqp_channel_sup} had child writer started with rabbit_writer:start_link(#Port<0.2823>, 1, 131072, rabbit_framing_amqp_0_9_1, <0.3781.0>, {<<"client 127.0.0.1:36301 -> 127.0.0.1:5672">>,1}) at <0.3782.0> exit with reason reached_max_restart_intensity in context shutdown
2017-08-06 12:45:05.484 [error] <0.3796.0>@rabbit_framing_amqp_0_9_1:shortstr_size:210 CRASH REPORT Process <0.3796.0> with 0 neighbours crashed with reason: bad argument in call to erlang:size([]) in rabbit_framing_amqp_0_9_1:shortstr_size/1 line 210
2017-08-06 12:45:05.484 [error] <0.3793.0> Supervisor {<0.3793.0>,amqp_channel_sup} had child writer started with rabbit_writer:start_link(#Port<0.2825>, 1, 131072, rabbit_framing_amqp_0_9_1, <0.3795.0>, {<<"client 127.0.0.1:34055 -> 127.0.0.1:5672">>,1}) at <0.3796.0> exit with reason badarg in context child_terminated

我正在使用这个库 https://github.com/jbrisbin/amqp_client 因为它有钢筋。我正在为我的项目使用钢筋。

可能是我写错了什么,因为我对 erlang 还很陌生。这是我的第一个 Live in Erlang 项目。我正在使用 ranch 作为 tcp 客户端接受器。我的客户端处理程序是 gen_fsm.

代码片段我正在使用

init({Ref, Socket, Transport, Mod, _Opts=[]})->
        process_flag(trap_exit, true),
        ok = ranch:accept_ack(Ref),
        ok = Transport:setopts(Socket, [{active, once}]),
        {ok, {RemoteIp, _Port}} = inet:peername(Socket),
        lager:info("New Client Connection From ~w Socket ~w", [RemoteIp, Socket]),
        {ok, RabbitConnection} = amqp_connection:start(#amqp_params_network{}),
        {ok, RabbitChannel} = amqp_connection:open_channel(RabbitConnection),
        InitTimerRef = erlang:start_timer(30000, self(), session_init_timer_laps),
        gen_fsm:enter_loop(?MODULE, [], open, #state{socket=Socket, transport=Transport, buffer= <<>>, mod=Mod, timers=#session_timers{session_init_timer=InitTimerRef}, sequence_number=1, rabbitmq_conn=RabbitConnection, rabbitmq_channel=RabbitChannel, remote_ip=RemoteIp}).

此外,每当我遇到这个问题时,我的牧场套接字监听器就会抛出以下错误。

<0.815.0> Ranch acceptor reducing accept rate: out of file descriptors

你 运行 out of file descriptors 这意味着你打开了太多资源而没有关闭它们(最有可能的连接)。

您可以增加 file descriptors,但您需要监控您的客户端并检查它正在使用的资源。

注意您使用的客户端有点旧,官方的 amqp rabbitmq 客户端在 hex 存储库上。 (https://hex.pm/packages/amqp_client) 你应该在你的项目中使用它:

{amqp_client, "3.6.10"}