服务端订阅EMQX经常出现断开重连

EMQX版本:4.3.22
设备连接EMQX上报数据,服务端通过订阅EMQX接收设备上报数据,发现服务端订阅EMQX经常出现连接断开重连的情况,连接断开的时间点查询EMQX的日志,找到了下面的信息,这个是什么原因?
2024-04-26T14:15:45.141782+08:00 [error] CMP-MQTT-cdI0Z2@192.168.0.89:58402 crasher: initial call: emqx_connection:init/4, pid: <0.6768.526>, registered_name: , error: {badarg,[{erlang,byte_size,[{error,<<“$SYS/brokers/emqx-1@node1.emqx.io/clients/73AF9252-”>>,<<“ÿÿÿÿÿÿÿÿÿÿÿÿ/connected”>>}],},{emqx_frame,serialize_utf8_string,1,[{file,“emqx_frame.erl”},{line,796}]},{emqx_frame,serialize_variable,2,[{file,“emqx_frame.erl”},{line,625}]},{emqx_frame,serialize,2,[{file,“emqx_frame.erl”},{line,565}]},{emqx_frame,serialize_pkt,2,[{file,“emqx_frame.erl”},{line,552}]},{emqx_connection,‘-serialize_and_inc_stats_fun/1-fun-2-’,2,[{file,“emqx_connection.erl”},{line,681}]},{lists,map,2,[{file,“lists.erl”},{line,1243}]},{emqx_connection,handle_outgoing,2,[{file,“emqx_connection.erl”},{line,674}]},{emqx_connection,process_msg,2,[{file,“emqx_connection.erl”},{line,356}]},{emqx_connection,process_msg,2,[{file,“emqx_connection.erl”},{line,362}]},{emqx_connection,handle_recv,3,[{file,“emqx_connection.erl”},{line,320}]},{proc_lib,wake_up,3,[{file,“proc_lib.erl”},{line,236}]}]}, ancestors: [<0.1961.0>,<0.1960.0>,esockd_sup,<0.1587.0>], message_queue_len: 0, messages: , links: [<0.1961.0>], dictionary: [{recv_pkt,16963},{send_pkt,23157},{‘$logger_metadata$’,#{clientid => “CMP-MQTT-cdI0Z2”,peername => “192.168.0.89:58402”}},{send_msg,15331},{recv_msg,7824},{rand_seed,{#{bits => 58,jump => #Fun<rand.3.47293030>,next => #Fun<rand.0.47293030>,type => exsss,uniform => #Fun<rand.1.47293030>,uniform_n => #Fun<rand.2.47293030>},[164900240688330451|203363150805555421]}},{incoming_pubs,36},{outgoing_bytes,21038},{guid,{1714112142514651,87119351650928,7824}},{outgoing_pubs,80},{incoming_bytes,4474}], trap_exit: false, status: running, heap_size: 4185, stack_size: 28, reductions: 20105916; neighbours:

这个应该是你使用的 topic 不是 utf8 的。导致这个断开了。
你订阅了connected事件,他的 topic 格式是{clientid}/connected
然后你使用的 clientid 不是 utf8 的,他就 crash 掉了。

建议不要使用这种格式的 clientid,来避开这个问题。

好的,我试试看处理下这个编码问题

clientid这个是由设备端控制的,设备测的开发我们无法控制,他们的clientId编码不对了就会导致这个断开,有没有什么更改的解决办法

5.x版本在连接时可以设置clientid替换,被用户名、证书中的字段或证书内容所覆盖