环境
- EMQX 版本:5.4.1
- 操作系统版本:ubuntu22.4
重现此问题的步骤
- 嵌入式团队开发的网关通过mqtt连接上EMQX
- 将网关断电重启
- EMQX自定义插件给我们回应的连接和断开时间顺序不对
4.先回应连接事件、再回应断开连接,结果网关还连接在Broker上
连接报文:
emqx_plugin_hook:on_client_connected/3(110), peername: 192.168.20.1:42800, clientid: a1gmxxxxxxT.xxxxxxxx|, clientinfo: #{clientid => <<“a1gmxxxxxxT.xxxxxxxx|”>>,cn => undefined,dn => undefined,enable_authn => true,is_bridge => false,is_superuser => false,listener => ‘tcp:default’,mountpoint => undefined,peerhost => {192,168,20,1},peerport => 42800,protocol => mqtt,sockport => 1883,username => <<“1FlOxxxxxxx6T”>>,zone => default}, connInfo: #{clean_start => true,clientid => <<“a1gmxxxxxxT.xxxxxxxx|”>>,conn_mod => emqx_connection,conn_props => #{},connected_at => 1732514733921,expiry_interval => 0,keepalive => 150,peercert => ,peername => {{192,168,20,1},42800},proto_name => <<“MQTT”>>,proto_ver => 4,receive_maximum => 32,sockname => {{192,168,20,135},1883},socktype => proxy,username => <<“1FlOxxxxxxx6T”>>}
断开连接报文:
emqx_plugin_hook:on_client_disconnected/4(132), peername: 192.168.20.1:46714, clientid: a1gmxxxxxxT.xxxxxxxx|, clientinfo: #{clientid => <<“a1gmxxxxxxT.xxxxxxxx|,”>>,cn => undefined,dn => undefined,enable_authn => true,is_bridge => false,is_superuser => false,listener => ‘tcp:default’,mountpoint => undefined,peerhost => {192,168,20,1},peerport => 46714,protocol => mqtt,sockport => 1883,username => <<“1FlOxxxxxxx6T”>>,zone => default}, conninfo: #{clean_start => true,clientid => <<“a1gmxxxxxxT.xxxxxxxx|,”>>,conn_mod => emqx_connection,conn_props => #{},connected_at => 1732514497884,disconnected_at => 1732514733998,expiry_interval => 0,keepalive => 150,peername => {{192,168,20,1},46714},proto_name => <<“MQTT”>>,proto_ver => 4,receive_maximum => 32,sockname => {{192,168,20,135},1883},socktype => proxy,username => <<“1FlOxxxxxxx6T”>>}, reason: tcp_closed
预期行为
1、连接与断开连接顺序问题,应该是断开连接在前,连接在后
2、reason原因问题,我们抓取嵌入式那边tcp连接报文,没看到FIN数据包
实际行为
连接在前,断开连接在后, 这就导致我们很难判断该设备最新的状态