出现shutdown,tcp_closed,自动断开连接

我是EMQX小白,大佬们帮忙看一下~
在一台电脑上,用两个matlab文件分别连接mqtt进行数据通信。在运行第二个程序时,第一个连接会自动断开,是什么原因呢?
(msg: terminate
reason: {shutdown,tcp_closed})

环境

  • EMQX 版本:4.4.18
  • 操作系统版本:Windows 10

重现此问题的步骤

  1. 运行central_unit
  2. 运行robots

预期行为

实际行为

central_unit的日志:

2023-06-21T10:43:35.131000+08:00 [debug] 127.0.0.1:1229 [Channel] RECV CONNECT(Q0, R0, D0, ClientId=central_unit, ProtoName=MQTT, ProtoVsn=4, CleanStart=true, KeepAlive=60, Username=undefined, Password=undefined)
2023-06-21T10:43:35.131000+08:00 [debug] 127.0.0.1:1229     client_id: <<"central_unit">>
    msg: insert_channel_info
2023-06-21T10:43:35.131000+08:00 [debug] 127.0.0.1:1229 [MQTT] SEND CONNACK(Q0, R0, D0, AckFlags=0, ReasonCode=0)
2023-06-21T10:43:35.131000+08:00 [debug] 127.0.0.1:1229 [MQTT] RECV <<130,17,0,1,0,12,114,111,98,111,116,115,95,115,116,97,116,101,0>>
2023-06-21T10:43:35.131000+08:00 [debug] 127.0.0.1:1229 [MQTT] RECV SUBSCRIBE(Q1, R0, D0, PacketId=1, TopicFilters=[{<<"robots_state">>,#{nl => 0,qos => 0,rap => 0,rh => 0}}])
2023-06-21T10:43:35.131000+08:00 [info] 127.0.0.1:1229 central_unit SUBSCRIBE robots_state: Options: #{nl => 0,qos => 0,rap => 0,rh => 0,sub_props => #{}}
2023-06-21T10:43:35.131000+08:00 [debug] 127.0.0.1:1229 [MQTT] SEND SUBACK(Q0, R0, D0, PacketId=1, ReasonCodes=[0])
2023-06-21T10:43:56.748000+08:00 [debug] 127.0.0.1:1229 [MQTT] SEND PUBLISH(Q0, R0, D0, Topic=robots_state, PacketId=undefined, Payload=<<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>)
2023-06-21T10:43:56.748000+08:00 [info] 127.0.0.1:1229     msg: terminate
    reason: {shutdown,tcp_closed}

robots的日志:

2023-06-21T10:43:55.003000+08:00 [debug] 127.0.0.1:1231 [Channel] RECV CONNECT(Q0, R0, D0, ClientId=robots, ProtoName=MQTT, ProtoVsn=4, CleanStart=true, KeepAlive=60, Username=undefined, Password=undefined)
2023-06-21T10:43:55.003000+08:00 [debug] 127.0.0.1:1231     client_id: <<"robots">>
    msg: insert_channel_info
2023-06-21T10:43:55.003000+08:00 [debug] 127.0.0.1:1231 [MQTT] SEND CONNACK(Q0, R0, D0, AckFlags=0, ReasonCode=0)
2023-06-21T10:43:55.003000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV <<130,15,0,1,0,10,97,108,108,111,99,97,116,105,111,110,0>>
2023-06-21T10:43:55.003000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV SUBSCRIBE(Q1, R0, D0, PacketId=1, TopicFilters=[{<<"allocation">>,#{nl => 0,qos => 0,rap => 0,rh => 0}}])
2023-06-21T10:43:55.003000+08:00 [info] 127.0.0.1:1231 robots SUBSCRIBE allocation: Options: #{nl => 0,qos => 0,rap => 0,rh => 0,sub_props => #{}}
2023-06-21T10:43:55.003000+08:00 [debug] 127.0.0.1:1231 [MQTT] SEND SUBACK(Q0, R0, D0, PacketId=1, ReasonCodes=[0])
2023-06-21T10:43:56.748000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV <<48,84,0,12,114,111,98,111,116,115,95,115,116,97,116,101,123,34,120,34,58,91,91,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,93,44,91,45,49,44,45,48,46,53,44,48,44,48,46,53,44,49,93,44,91,48,44,48,44,48,44,48,44,48,93,93,44,34,116,34,58,48,125>>
2023-06-21T10:43:56.748000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV PUBLISH(Q0, R0, D0, Topic=robots_state, PacketId=undefined, Payload=<<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>)
2023-06-21T10:43:56.748000+08:00 [info] 127.0.0.1:1231 PUBLISH to robots_state: <<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>
2023-06-21T10:43:56.758000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV <<48,84,0,12,114,111,98,111,116,115,95,115,116,97,116,101,123,34,120,34,58,91,91,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,93,44,91,45,49,44,45,48,46,53,44,48,44,48,46,53,44,49,93,44,91,48,44,48,44,48,44,48,44,48,93,93,44,34,116,34,58,48,125>>
2023-06-21T10:43:56.758000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV PUBLISH(Q0, R0, D0, Topic=robots_state, PacketId=undefined, Payload=<<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>)
2023-06-21T10:43:56.758000+08:00 [info] 127.0.0.1:1231 PUBLISH to robots_state: <<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>
2023-06-21T10:43:56.758000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV <<48,84,0,12,114,111,98,111,116,115,95,115,116,97,116,101,123,34,120,34,58,91,91,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,93,44,91,45,49,44,45,48,46,53,44,48,44,48,46,53,44,49,93,44,91,48,44,48,44,48,44,48,44,48,93,93,44,34,116,34,58,48,125>>
2023-06-21T10:43:56.758000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV PUBLISH(Q0, R0, D0, Topic=robots_state, PacketId=undefined, Payload=<<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>)
2023-06-21T10:43:56.758000+08:00 [info] 127.0.0.1:1231 PUBLISH to robots_state: <<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>
2023-06-21T10:43:56.758000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV <<48,84,0,12,114,111,98,111,116,115,95,115,116,97,116,101,123,34,120,34,58,91,91,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,93,44,91,45,49,44,45,48,46,53,44,48,44,48,46,53,44,49,93,44,91,48,44,48,44,48,44,48,44,48,93,93,44,34,116,34,58,48,125>>
2023-06-21T10:43:56.758000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV PUBLISH(Q0, R0, D0, Topic=robots_state, PacketId=undefined, Payload=<<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>)
2023-06-21T10:43:56.758000+08:00 [info] 127.0.0.1:1231 PUBLISH to robots_state: <<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>
2023-06-21T10:43:56.768000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV <<48,84,0,12,114,111,98,111,116,115,95,115,116,97,116,101,123,34,120,34,58,91,91,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,93,44,91,45,49,44,45,48,46,53,44,48,44,48,46,53,44,49,93,44,91,48,44,48,44,48,44,48,44,48,93,93,44,34,116,34,58,48,125>>
2023-06-21T10:43:56.768000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV PUBLISH(Q0, R0, D0, Topic=robots_state, PacketId=undefined, Payload=<<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>)
2023-06-21T10:43:56.768000+08:00 [info] 127.0.0.1:1231 PUBLISH to robots_state: <<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>
2023-06-21T10:43:56.768000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV <<48,84,0,12,114,111,98,111,116,115,95,115,116,97,116,101,123,34,120,34,58,91,91,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,93,44,91,45,49,44,45,48,46,53,44,48,44,48,46,53,44,49,93,44,91,48,44,48,44,48,44,48,44,48,93,93,44,34,116,34,58,48,125>>
2023-06-21T10:43:56.768000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV PUBLISH(Q0, R0, D0, Topic=robots_state, PacketId=undefined, Payload=<<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>)
2023-06-21T10:43:56.768000+08:00 [info] 127.0.0.1:1231 PUBLISH to robots_state: <<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>
2023-06-21T10:43:56.768000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV <<48,84,0,12,114,111,98,111,116,115,95,115,116,97,116,101,123,34,120,34,58,91,91,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,93,44,91,45,49,44,45,48,46,53,44,48,44,48,46,53,44,49,93,44,91,48,44,48,44,48,44,48,44,48,93,93,44,34,116,34,58,48,125>>
2023-06-21T10:43:56.768000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV PUBLISH(Q0, R0, D0, Topic=robots_state, PacketId=undefined, Payload=<<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>)
2023-06-21T10:43:56.768000+08:00 [info] 127.0.0.1:1231 PUBLISH to robots_state: <<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>
2023-06-21T10:43:56.768000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV <<48,84,0,12,114,111,98,111,116,115,95,115,116,97,116,101,123,34,120,34,58,91,91,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,93,44,91,45,49,44,45,48,46,53,44,48,44,48,46,53,44,49,93,44,91,48,44,48,44,48,44,48,44,48,93,93,44,34,116,34,58,48,125>>
2023-06-21T10:43:56.768000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV PUBLISH(Q0, R0, D0, Topic=robots_state, PacketId=undefined, Payload=<<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>)
2023-06-21T10:43:56.768000+08:00 [info] 127.0.0.1:1231 PUBLISH to robots_state: <<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>
2023-06-21T10:43:56.768000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV <<48,84,0,12,114,111,98,111,116,115,95,115,116,97,116,101,123,34,120,34,58,91,91,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,93,44,91,45,49,44,45,48,46,53,44,48,44,48,46,53,44,49,93,44,91,48,44,48,44,48,44,48,44,48,93,93,44,34,116,34,58,48,125>>
2023-06-21T10:43:56.768000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV PUBLISH(Q0, R0, D0, Topic=robots_state, PacketId=undefined, Payload=<<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>)
2023-06-21T10:43:56.768000+08:00 [info] 127.0.0.1:1231 PUBLISH to robots_state: <<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>
2023-06-21T10:43:56.778000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV <<48,84,0,12,114,111,98,111,116,115,95,115,116,97,116,101,123,34,120,34,58,91,91,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,93,44,91,45,49,44,45,48,46,53,44,48,44,48,46,53,44,49,93,44,91,48,44,48,44,48,44,48,44,48,93,93,44,34,116,34,58,48,125>>
2023-06-21T10:43:56.778000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV PUBLISH(Q0, R0, D0, Topic=robots_state, PacketId=undefined, Payload=<<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>)
2023-06-21T10:43:56.778000+08:00 [info] 127.0.0.1:1231 PUBLISH to robots_state: <<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>
2023-06-21T10:43:56.778000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV <<48,84,0,12,114,111,98,111,116,115,95,115,116,97,116,101,123,34,120,34,58,91,91,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,93,44,91,45,49,44,45,48,46,53,44,48,44,48,46,53,44,49,93,44,91,48,44,48,44,48,44,48,44,48,93,93,44,34,116,34,58,48,125>>
2023-06-21T10:43:56.778000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV PUBLISH(Q0, R0, D0, Topic=robots_state, PacketId=undefined, Payload=<<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>)
2023-06-21T10:43:56.778000+08:00 [info] 127.0.0.1:1231 PUBLISH to robots_state: <<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>
2023-06-21T10:43:56.778000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV <<48,84,0,12,114,111,98,111,116,115,95,115,116,97,116,101,123,34,120,34,58,91,91,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,93,44,91,45,49,44,45,48,46,53,44,48,44,48,46,53,44,49,93,44,91,48,44,48,44,48,44,48,44,48,93,93,44,34,116,34,58,48,125>>
2023-06-21T10:43:56.778000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV PUBLISH(Q0, R0, D0, Topic=robots_state, PacketId=undefined, Payload=<<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>)
2023-06-21T10:43:56.778000+08:00 [info] 127.0.0.1:1231 PUBLISH to robots_state: <<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>
2023-06-21T10:43:56.778000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV <<48,84,0,12,114,111,98,111,116,115,95,115,116,97,116,101,123,34,120,34,58,91,91,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,93,44,91,45,49,44,45,48,46,53,44,48,44,48,46,53,44,49,93,44,91,48,44,48,44,48,44,48,44,48,93,93,44,34,116,34,58,48,125>>
2023-06-21T10:43:56.788000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV PUBLISH(Q0, R0, D0, Topic=robots_state, PacketId=undefined, Payload=<<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>)
2023-06-21T10:43:56.788000+08:00 [info] 127.0.0.1:1231 PUBLISH to robots_state: <<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>
2023-06-21T10:43:56.788000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV <<48,84,0,12,114,111,98,111,116,115,95,115,116,97,116,101,123,34,120,34,58,91,91,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,44,49,46,54,53,93,44,91,45,49,44,45,48,46,53,44,48,44,48,46,53,44,49,93,44,91,48,44,48,44,48,44,48,44,48,93,93,44,34,116,34,58,48,125>>
2023-06-21T10:43:56.788000+08:00 [debug] 127.0.0.1:1231 [MQTT] RECV PUBLISH(Q0, R0, D0, Topic=robots_state, PacketId=undefined, Payload=<<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>)
2023-06-21T10:43:56.788000+08:00 [info] 127.0.0.1:1231 PUBLISH to robots_state: <<"{\"x\":[[1.65,1.65,1.65,1.65,1.65],[-1,-0.5,0,0.5,1],[0,0,0,0,0]],\"t\":0}">>

robots 日志中第一行连接时间是 10:43:55
central_unit 断开时间是 10:43:56
两个客户端id 没有冲突,看一下是不是你的客户端实是不是在同一时刻只支持有一个 MQTT 连接。

应该不是,因为在别人电脑运行是没问题的。然后:
1、我尝试了如果交换运行次序,先运行robots,再运行central_unit,最终的结果还是robots保持连接,central_unit断开连接。
2、看日志,都是robots和central_unit同时连接的情况下,central_unit接收到订阅的消息后马上就断开

可以尝试 wireshark 抓包看一下具体情况,另外就是需要你调查一下 matlab 客户端连接的日志信息。
现在看起来连接不是 EMQX 主动断开的,从你在其他机器上的运行情况看也是这样的。

感谢,重新下了最高版本的客户端,问题就解决了