客户端每回第一次连接都失败报错,第二次连接则稳定(3秒后自动连接)。

emqx版本:emqx-5.0.16-windows-amd64
客户端:C# mqttnet 2.0.15

emqx报错:
2023-03-20T11:28:50.805000+08:00 [error] REPORT_CB/2 CRASH: [{mfa,[“proc_lib”,“:”,“crash_report”,“/4”]},{line,525},{peername,“192.168.0.3:57349”},{clientid,“root”},{label,{proc_lib,crash}},{report,[[{initial_call,{emqx_connection,init,[‘Argument__1’,‘Argument__2’,‘Argument__3’,‘Argument__4’]}},{pid,<0.19640.20>},{registered_name,[]},{error_info,{error,frame_serialize_error,[{emqx_connection,‘-serialize_and_inc_stats_fun/1-fun-0-’,2,[{file,“emqx_connection.erl”},{line,855}]},{lists,map,2,[{file,“lists.erl”},{line,1243}]},{emqx_connection,handle_outgoing,2,[{file,“emqx_connection.erl”},{line,820}]},{emqx_connection,process_msg,2,[{file,“emqx_connection.erl”},{line,471}]},{emqx_connection,process_msg,2,[{file,“emqx_connection.erl”},{line,477}]},{emqx_connection,handle_recv,3,[{file,“emqx_connection.erl”},{line,433}]},{proc_lib,wake_up,3,[{file,“proc_lib.erl”},{line,236}]}]}},{ancestors,[<0.2082.0>,<0.2081.0>,esockd_sup,<0.1861.0>]},{message_queue_len,0},{messages,[]},{links,[<0.2082.0>]},{dictionary,[{{subscribe,<<“+/jk/info”>>},{allow,1679282924343}},{‘$logger_metadata$’,#{clientid => <<“root”>>,peername => “192.168.0.3:57349”}},{{subscribe,<<“$SYS/brokers/+/clients/+/connected”>>},{allow,1679282924343}},{incoming_pubs,1},{outgoing_bytes,13},{authz_keys_q,{[{publish,<<“clocksync”>>},{subscribe,<<“+/jk/info”>>},{subscribe,<<“$SYS/brokers/+/clients/+/disconnected”>>},{subscribe,<<“$SYS/brokers/+/clients/+/connected”>>},{subscribe,<<“info/+/+”>>}],[{subscribe,<<“audio/#”>>}]}},{guid,{1679282929347032,268556050648248,1}},{authz_cache_size,6},{{subscribe,<<“$SYS/brokers/+/clients/+/disconnected”>>},{allow,1679282924343}},{{publish,<<“clocksync”>>},{allow,1679282929347}},{send_pkt,2},{incoming_bytes,172},{{subscribe,<<“info/+/+”>>},{allow,1679282924342}},{{subscribe,<<“audio/#”>>},{allow,1679282924342}},{‘recv_msg.qos0’,1},{recv_msg,1},{recv_pkt,3}]},{trap_exit,false},{status,running},{heap_size,6772},{stack_size,29},{reductions,772413}],[]]}]; Reason: {error,function_clause,[{proc_lib,report_cb,[[{mfa,[“proc_lib”,“:”,“crash_report”,“/4”]},{line,525},{peername,“192.168.0.3:57349”},{clientid,“root”},{label,{proc_lib,crash}},{report,[[{initial_call,{emqx_connection,init,[‘Argument__1’,‘Argument__2’,‘Argument__3’,‘Argument__4’]}},{pid,<0.19640.20>},{registered_name,[]},{error_info,{error,frame_serialize_error,[{emqx_connection,‘-serialize_and_inc_stats_fun/1-fun-0-’,2,[{file,“emqx_connection.erl”},{line,855}]},{lists,map,2,[{file,“lists.erl”},{line,1243}]},{emqx_connection,handle_outgoing,2,[{file,“emqx_connection.erl”},{line,820}]},{emqx_connection,process_msg,2,[{file,“emqx_connection.erl”},{line,471}]},{emqx_connection,process_msg,2,[{file,“emqx_connection.erl”},{line,477}]},{emqx_connection,handle_recv,3,[{file,“emqx_connection.erl”},{line,433}]},{proc_lib,wake_up,3,[{file,“proc_lib.erl”},{line,236}]}]}},{ancestors,[<0.2082.0>,<0.2081.0>,esockd_sup,<0.1861.0>]},{message_queue_len,0},{messages,[]},{links,[<0.2082.0>]},{dictionary,[{{subscribe,<<“+/jk/info”>>},{allow,1679282924343}},{‘$logger_metadata$’,#{clientid => <<“root”>>,peername => “192.168.0.3:57349”}},{{subscribe,<<“$SYS/brokers/+/clients/+/connected”>>},{allow,1679282924343}},{incoming_pubs,1},{outgoing_bytes,13},{authz_keys_q,{[{publish,<<“clocksync”>>},{subscribe,<<“+/jk/info”>>},{subscribe,<<“$SYS/brokers/+/clients/+/disconnected”>>},{subscribe,<<“$SYS/brokers/+/clients/+/connected”>>},{subscribe,<<“info/+/+”>>}],[{subscribe,<<“audio/#”>>}]}},{guid,{1679282929347032,268556050648248,1}},{authz_cache_size,6},{{subscribe,<<“$SYS/brokers/+/clients/+/disconnected”>>},{allow,1679282924343}},{{publish,<<“clocksync”>>},{allow,1679282929347}},{send_pkt,2},{incoming_bytes,172},{{subscribe,<<“info/+/+”>>},{allow,1679282924342}},{{subscribe,<<“audio/#”>>},{allow,1679282924342}},{‘recv_msg.qos0’,1},{recv_msg,1},{recv_pkt,3}]},{trap_exit,false},{status,running},{heap_size,6772},{stack_size,29},{reductions,772413}],[]]}],#{chars_limit => unlimited,depth => 100,single_line => true}],[{file,“proc_lib.erl”},{line,774}]}]}
2023-03-20T11:28:50.806000+08:00 [error] label: {error_logger,error_report}, report: [{supervisor,‘esockd_connection_sup - <0.2082.0>’},{errorContext,connection_crashed},{reason,{frame_serialize_error,[{emqx_connection,‘-serialize_and_inc_stats_fun/1-fun-0-’,2,[{file,“emqx_connection.erl”},{line,855}]},{lists,map,2,[{file,“lists.erl”},{line,1243}]},{emqx_connection,handle_outgoing,2,[{file,“emqx_connection.erl”},{line,820}]},{emqx_connection,process_msg,2,[{file,“emqx_connection.erl”},{line,471}]},{emqx_connection,process_msg,2,[{file,“emqx_connection.erl”},{line,477}]},{emqx_connection,handle_recv,3,[{file,“emqx_connection.erl”},{line,433}]},{proc_lib,wake_up,3,[{file,“proc_lib.erl”},{line,236}]}]}},{offender,[{pid,<0.19640.20>},{name,connection},{mfargs,{emqx_connection,start_link,[#{enable_authn => true,limiter => #{bytes_in => #{capacity => 1099511627776,initial => 0,rate => infinity},client => #{bytes_in => #{capacity => 1099511627776,divisible => false,failure_strategy => force,initial => 0,low_watermark => 0,max_retry_time => 10000,rate => infinity},connection => #{capacity => 1099511627776,divisible => false,failure_strategy => force,initial => 0,low_watermark => 0,max_retry_time => 10000,rate => infinity},message_in => #{capacity => 1099511627776,divisible => false,failure_strategy => force,initial => 0,low_watermark => 0,max_retry_time => 10000,rate => infinity},message_routing => #{capacity => 1099511627776,divisible => false,failure_strategy => force,initial => 0,low_watermark => 0,max_retry_time => 10000,rate => infinity}},connection => #{capacity => 1000,initial => 0,rate => 100.0},message_in => #{capacity => 1099511627776,initial => 0,rate => infinity},message_routing => #{capacity => 1099511627776,initial => 0,rate => infinity}},listener => {tcp,default},zone => default}]}}]}]

AI解释:
错误发生在2023年3月20日11:28:50,时区为GMT+8。错误消息表明,在处理来自ID为“root”、IP地址为“192.168.0.3:57349”的客户端的MQTT连接时,进程崩溃。

崩溃发生在第855行的模块“emqx-connection.erl”中的函数“-serialize-and-inc-stats-fun/1-fun-0-”中。错误消息表明崩溃是由“proc-lib”模块中的函数子句错误引起的,特别是在函数“report-cb/2”中。

报错场景:
用mqttnet第一次连接时会报错

已解决,更新mqttnet的版本到最新版,问题消失。