Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT over WebSocket, QoS 0 messages may not get sent before disconnection #1607

Open
ysfscream opened this issue May 25, 2023 · 2 comments
Open

Comments

@ysfscream
Copy link
Contributor

ysfscream commented May 25, 2023

Describe the bug
When using MQTT over WebSocket with QoS set to 0, I have encountered a situation where the publish callback is triggered before the message has been successfully sent. This causes the message not to get sent before the connection is ended. This issue occurs intermittently only with WebSocket connections, not with MQTT over TCP connections.

To Reproduce
Here is a simple code snippet that reproduces the issue:

const client = // initialize MQTT client with WebSocket
client.publish(topic, message, { qos: 0 }, (err, packet) => {
  if (err) {
    console.error('Publish failed:', err)
  } else {
    console.log('Publish succeeded:', packet)
    client.end()
  }
})

In the case of a WebSocket connection and QoS 0, the 'Publish succeeded' log may print before the message is actually sent.

Expected behavior
The publish callback should not be called until the message is successfully sent, even when using WebSocket and QoS 0.

Environment (please complete the following information):

  • OS: macOS
  • Node.js version: v16.14.2
  • MQTT.js version: 4.3.7

Additional context
The issue only occurs intermittently and with WebSocket connections, not other MQTT/TCP of connections.

@robertsLando
Copy link
Member

Could you submit a PR to fix this issue?

@robertsLando
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants