mqttjs / MQTT.js

The MQTT client for Node.js and the browser
Other
8.53k stars 1.41k forks source link

mqtt client receives msg with null topic in some cases #1503

Closed zhengguoxin closed 1 month ago

zhengguoxin commented 2 years ago

In most cases, mqtt client can receive the subscribed topic, but in some cases, mqtt client receives messages with null topic. I can reproduce this situation by trying to hibernate the server and then resume it.

But I don't know how to solve this problem when the received topic is null

image
doc-han commented 2 years ago

You will need to first figure out whether the null value is caused by the broker or the client library.

zhengguoxin commented 2 years ago

This is not caused by the broker, because when receive null topic, other clients can receive it normally. But when I restart nodejs, this mqtt client can receive correct topic value

tennessine commented 2 years ago

你用的什么broker,怎么能跑出来null topic

zhengguoxin commented 2 years ago

你用的什么broker,怎么能跑出来null topic

和broker无关,用的是emqx的。我找到规律了,当mqtt连接成功后,如果后续的代码有一个长时间的cpu密集运算,比如一个耗时很长的for循环,那么在循环中,实际上mqtt客户端没有和broke连接了(因为cpu被分配给循环)。等循环结束后,mqtt会自动重连成功,但是这个时候虽然可以接收信息,但是topic居然是null。

既然能收到消息,说明topic寻址是正常,而回调中topic为空,应该是这个mqtt的bug导致。

这个问题在部分场景下可以利用 v5版本的 properties特性来携带topic,但是这个场景不能解决所有的问题,

希望有大侠能解决这个bug,谢谢

github-actions[bot] commented 1 year ago

This is an automated message to let you know that this issue has gone 365 days without any activity. In order to ensure that we work on issues that still matter, this issue will be closed in 14 days.

If this issue is still important, you can simply comment with a "bump" to keep it open.

Thank you for your contribution.

robertsLando commented 1 year ago

MQTT 5.0.0 BETA is now available! Try it out and give us feedback: npm i mqtt@beta. It may fix your issues

github-actions[bot] commented 1 month ago

This is an automated message to let you know that this issue has gone 365 days without any activity. In order to ensure that we work on issues that still matter, this issue will be closed in 14 days.

If this issue is still important, you can simply comment with a "bump" to keep it open.

Thank you for your contribution.

github-actions[bot] commented 1 month ago

This issue was automatically closed due to inactivity.