客户端被服务器踢下线

环境信息

  • EMQX 版本:4.4.4
  • 操作系统及版本:win
  • 其他

问题描述

这个设备已经正常运行几个月 了,,最近总是被服务器踢下线

配置文件及日志

Parse failed for {badmatch,{#{},<<116,111,119,101,114,109,113,116,116,1,227,101,121,74,116,90,88,78,122,89,87,100,108,97,87,81,105,79,105,73,52,79,84,103,50,77,84,69,121,77,84,73,49,79,84,65,52,78,84,99,52,78,84,81,121,77,87,70,104,89,109,73,50,77,109,69,53,78,71,73,122,77,67,73,115,73,109,49,108,100,71,86,121,98,110,86,116,73,106,111,105,77,122,81,119,78,84,65,121,77,68,73,122,77,106,69,120,77,68,69,49,77,68,65,119,78,122,81,52,79,67,73,115,73,110,78,112,90,50,53,104,98,71,120,108,100,109,86,115,73,106,111,121,78,67,119,105,90,71,70,48,89,88,82,53,99,71,85,105,79,106,73,115,73,109,90,121,98,51,112,108,98,105,73,54,77,67,119,105,100,71,108,116,90,83,73,54,77,84,89,49,78,84,73,50,77,106,65,119,77,68,65,119,77,67,119,105,97,51,100,111,73,106,111,105,78,68,85,51,76,106,81,48,73,105,119,105,98,71,57,118,99,68,70,114,100,50,103,105,79,105,73,48,78,84,99,117,78,68,81,105,102,81,61,61>>}}
[{emqx_frame,parse_packet,3,[{file,"emqx_frame.erl"},{line,260}]},{emqx_frame,parse_frame,4,[{file,"emqx_frame.erl"},{line,201}]},{emqx_connection,parse_incoming,3,[{file,"emqx_connection.erl"},{line,655}]},{emqx_connection,handle_msg,2,[{file,"emqx_connection.erl"},{line,648}]},{emqx_connection,process_msg,2,[{file,"emqx_connection.erl"},{line,394}]},{emqx_connection,handle_recv,3,[{file,"emqx_connection.erl"},{line,358}]},{proc_lib,wake_up,3,[{file,"proc_lib.erl"},{line,236}]}]
Frame data:<<42,129,2,0,9,116,111,119,101,114,109,113,116,116,1,227,101,121,74,116,90,88,78,122,89,87,100,108,97,87,81,105,79,105,73,52,79,84,103,50,77,84,69,121,77,84,73,49,79,84,65,52,78,84,99,52,78,84,81,121,77,87,70,104,89,109,73,50,77,109,69,53,78,71,73,122,77,67,73,115,73,109,49,108,100,71,86,121,98,110,86,116,73,106,111,105,77,122,81,119,78,84,65,121,77,68,73,122,77,106,69,120,77,68,69,49,77,68,65,119,78,122,81,52,79,67,73,115,73,110,78,112,90,50,53,104,98,71,120,108,100,109,86,115,73,106,111,121,78,67,119,105,90,71,70,48,89,88,82,53,99,71,85,105,79,106,73,115,73,109,90,121,98,51,112,108,98,105,73,54,77,67,119,105,100,71,108,116,90,83,73,54,77,84,89,49,78,84,73,50,77,106,65,119,77,68,65,119,77,67,119,105,97,51,100,111,73,106,111,105,78,68,85,51,76,106,81,48,73,105,119,105,98,71,57,118,99,68,70,114,100,50,103,105,79,105,73,48,78,84,99,117,78,68,81,105,102,81,61,61>>
2022-06-20T16:04:11.470000+08:00 [debug] 117.61.242.199:23181 [MQTT] Force to close the socket due to {badmatch,
                                         {#{},
                                          <<116,111,119,101,114,109,113,116,
                                            116,1,227,101,121,74,116,90,88,
                                            78,122,89,87,100,108,97,87,81,
                                            105,79,105,73,52,79,84,103,50,77,
                                            84,69,121,77,84,73,49,79,84,65,
                                            52,78,84,99,52,78,84,81,121,77,
                                            87,70,104,89,109,73,50,77,109,69,
                                            53,78,71,73,122,77,67,73,115,73,
                                            109,49,108,100,71,86,121,98,110,
                                            86,116,73,106,111,105,77,122,81,
                                            119,78,84,65,121,77,68,73,122,77,
                                            106,69,120,77,68,69,49,77,68,65,
                                            119,78,122,81,52,79,67,73,115,73,
                                            110,78,112,90,50,53,104,98,71,
                                            120,108,100,109,86,115,73,106,
                                            111,121,78,67,119,105,90,71,70,
                                            48,89,88,82,53,99,71,85,105,79,
                                            106,73,115,73,109,90,121,98,51,
                                            112,108,98,105,73,54,77,67,119,
                                            105,100,71,108,116,90,83,73,54,
                                            77,84,89,49,78,84,73,50,77,106,
                                            65,119,77,68,65,119,77,67,119,
                                            105,97,51,100,111,73,106,111,105,
                                            78,68,85,51,76,106,81,48,73,105,
                                            119,105,98,71,57,118,99,68,70,
                                            114,100,50,103,105,79,105,73,48,
                                            78,84,99,117,78,68,81,105,102,81,
                                            61,61>>}}
2022-06-20T16:04:14.057000+08:00 [debug] 117.61.242.199:26178 [Channel] RECV CONNECT(Q0, R0, D0ClientId=340502023

日志中的错误是报文协议栈不对,解析失败。
但是你说的【这台设备】是日志中的错误吗?可以使用日志追踪看一下设备的情况

2022-06-20T11:29:03.925000+08:00 [info] 117.61.242.199:8136 msg: terminate
reason: {shutdown,takeovered}
2022-06-20T11:29:03.925000+08:00 [debug] 117.61.242.199:21748 client_id: <<“3405020232110150007488”>>
msg: insert_channel_info
2022-06-20T11:29:03.925000+08:00 [debug] 117.61.242.199:21748 [MQTT] SEND CONNACK(Q0, R0, D0AckFlags=1, ReasonCode=0)
2022-06-20T11:29:04.375000+08:00 [debug] 117.61.242.199:21748 [MQTT] RECV <<42,129,2,0,9,116,111,119,101,114,109,113,116,116,1,227,101,121,74,116,90,88,78,122,89,87,100,108,97,87,81,105,79,105,73,52,79,84,103,50,77,84,69,121,77,84,73,49,79,84,65,52,78,84,99,52,78,84,81,121,77,87,70,104,89,109,73,50,77,109,69,53,78,71,73,122,77,67,73,115,73,109,49,108,100,71,86,121,98,110,86,116,73,106,111,105,77,122,81,119,78,84,65,121,77,68,73,122,77,106,69,120,77,68,69,49,77,68,65,119,78,122,81,52,79,67,73,115,73,110,78,112,90,50,53,104,98,71,120,108,100,109,86,115,73,106,111,121,78,67,119,105,90,71,70,48,89,88,82,53,99,71,85,105,79,106,73,115,73,109,90,121,98,51,112,108,98,105,73,54,77,67,119,105,100,71,108,116,90,83,73,54,77,84,89,49,78,84,73,50,77,106,65,119,77,68,65,119,77,67,119,105,97,51,100,111,73,106,111,105,78,68,85,51,76,106,81,48,73,105,119,105,98,71,57,118,99,68,70,114,100,50,103,105,79,105,73,48,78,84,99,117,78,68,81,105,102,81,61,61>>
2022-06-20T11:29:04.376000+08:00 [error] 117.61.242.199:21748 [MQTT]
Parse failed for {badmatch,{#{},<<116,111,119,101,114,109,113,116,116,1,227,101,121,74,116,90,88,78,122,89,87,100,108,97,87,81,105,79,105,73,52,79,84,103,50,77,84,69,121,77,84,73,49,79,84,65,52,78,84,99,52,78,84,81,121,77,87,70,104,89,109,73,50,77,109,69,53,78,71,73,122,77,67,73,115,73,109,49,108,100,71,86,121,98,110,86,116,73,106,111,105,77,122,81,119,78,84,65,121,77,68,73,122,77,106,69,120,77,68,69,49,77,68,65,119,78,122,81,52,79,67,73,115,73,110,78,112,90,50,53,104,98,71,120,108,100,109,86,115,73,106,111,121,78,67,119,105,90,71,70,48,89,88,82,53,99,71,85,105,79,106,73,115,73,109,90,121,98,51,112,108,98,105,73,54,77,67,119,105,100,71,108,116,90,83,73,54,77,84,89,49,78,84,73,50,77,106,65,119,77,68,65,119,77,67,119,105,97,51,100,111,73,106,111,105,78,68,85,51,76,106,81,48,73,105,119,105,98,71,57,118,99,68,70,114,100,50,103,105,79,105,73,48,78,84,99,117,78,68,81,105,102,81,61,61>>}}
[{emqx_frame,parse_packet,3,[{file,“emqx_frame.erl”},{line,260}]},{emqx_frame,parse_frame,4,[{file,“emqx_frame.erl”},{line,201}]},{emqx_connection,parse_incoming,3,[{file,“emqx_connection.erl”},{line,655}]},{emqx_connection,handle_msg,2,[{file,“emqx_connection.erl”},{line,648}]},{emqx_connection,process_msg,2,[{file,“emqx_connection.erl”},{line,394}]},{emqx_connection,handle_recv,3,[{file,“emqx_connection.erl”},{line,358}]},{proc_lib,wake_up,3,[{file,“proc_lib.erl”},{line,236}]}]
Frame data:<<42,129,2,0,9,116,111,119,101,114,109,113,116,116,1,227,101,121,74,116,90,88,78,122,89,87,100,108,97,87,81,105,79,105,73,52,79,84,103,50,77,84,69,121,77,84,73,49,79,84,65,52,78,84,99,52,78,84,81,121,77,87,70,104,89,109,73,50,77,109,69,53,78,71,73,122,77,67,73,115,73,109,49,108,100,71,86,121,98,110,86,116,73,106,111,105,77,122,81,119,78,84,65,121,77,68,73,122,77,106,69,120,77,68,69,49,77,68,65,119,78,122,81,52,79,67,73,115,73,110,78,112,90,50,53,104,98,71,120,108,100,109,86,115,73,106,111,121,78,67,119,105,90,71,70,48,89,88,82,53,99,71,85,105,79,106,73,115,73,109,90,121,98,51,112,108,98,105,73,54,77,67,119,105,100,71,108,116,90,83,73,54,77,84,89,49,78,84,73,50,77,106,65,119,77,68,65,119,77,67,119,105,97,51,100,111,73,106,111,105,78,68,85,51,76,106,81,48,73,105,119,105,98,71,57,118,99,68,70,114,100,50,103,105,79,105,73,48,78,84,99,117,78,68,81,105,102,81,61,61>>
2022-06-20T11:29:04.378000+08:00 [debug] 117.61.242.199:21748 [MQTT] Force to close the socket due to {badmatch,
{#{},
<<116,111,119,101,114,109,113,116,
116,1,227,101,121,74,116,90,88,
78,122,89,87,100,108,97,87,81,
105,79,105,73,52,79,84,103,50,77,
84,69,121,77,84,73,49,79,84,65,
52,78,84,99,52,78,84,81,121,77,
87,70,104,89,109,73,50,77,109,69,
53,78,71,73,122,77,67,73,115,73,
109,49,108,100,71,86,121,98,110,
86,116,73,106,111,105,77,122,81,
119,78,84,65,121,77,68,73,122,77,
106,69,120,77,68,69,49,77,68,65,
119,78,122,81,52,79,67,73,115,73,
110,78,112,90,50,53,104,98,71,
120,108,100,109,86,115,73,106,
111,121,78,67,119,105,90,71,70,
48,89,88,82,53,99,71,85,105,79,
106,73,115,73,109,90,121,98,51,
112,108,98,105,73,54,77,67,119,
105,100,71,108,116,90,83,73,54,
77,84,89,49,78,84,73,50,77,106,
65,119,77,68,65,119,77,67,119,
105,97,51,100,111,73,106,111,105,
78,68,85,51,76,106,81,48,73,105,
119,105,98,71,57,118,99,68,70,
114,100,50,103,105,79,105,73,48,
78,84,99,117,78,68,81,105,102,81,
61,61>>}}
2022-06-20T11:29:06.916000+08:00 [debug] 117.61.242.199:3479 [Channel] RECV CONNECT(Q0, R0, D0ClientId=3405020232110150007488, ProtoName=MQTT, ProtoVsn=4, CleanStart=false, KeepAlive=180, Username=holley, Password=******)
2022-06-20T11:29:06.916000+08:00 [info] 117.61.242.199:21748 msg: terminate
reason: {shutdown,takeovered}
2022-06-20T11:29:06.917000+08:00 [debug] 117.61.242.199:3479 client_id: <<“3405020232110150007488”>>
msg: insert_channel_info
2022-06-20T11:29:06.917000+08:00 [debug] 117.61.242.199:3479 [MQTT] SEND CONNACK(Q0, R0, D0AckFlags=1, ReasonCode=0)

这个就是跟踪日志

设备在互踢,检查一下设备的IP,是不是有多个设备同一个ID了

设备行为很复杂,也可能是异常下线或者其他的问题,但是最主要的就是设备的报文不合法了,不是标准的MQTT协议报文

是不是因为不合法的报文,服务器设备踢掉了,然后过了一段时间 设备又连上来了

很可能,这个最好的办法是抓包看,设备的网络流量能更清晰。

如何判断不是标准的mqtt协议报文?

抓包看是用什么工具吗

因为这个设备运行了很长一段时间,突然就不好了

win mac:Wireshark
linux: tcpdump

可以抓包出来使用wireshark解析一下,支持mqtt报文内容详细信息展示的

ok 感谢