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

Closed
ysfscream opened this issue May 25, 2023 · 4 comments
Closed
Labels

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

Copy link

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 github-actions bot added the stale label Jul 21, 2024
Copy link

github-actions bot commented Aug 4, 2024

This issue was automatically closed due to inactivity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants