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

The way sendPacket handles writeToStream return values is built on a number of false assumptions #1403

Open
vishnureddy17 opened this issue Jan 18, 2022 · 2 comments
Assignees

Comments

@vishnureddy17
Copy link
Member

vishnureddy17 commented Jan 18, 2022

This code (the way sendPacket handles writeToStream return values) is built on a number of false assumptions:

  1. It assumes that writeToStream will only return false if the packet was queued and is waiting to send. This is wrong. writeToStream can also fail if packet validation fails (in mqtt-packet/writeToStream.js) If this happens, sendPacket will wait for the stream to drain, then call the callback with no error.
  2. If the stream is full, and writeToStream returns false, it waits for all packets to send before calling any of their callbacks. Once all packets are sent, the drain event fires, and all callbacks get called at once. If the sending pattern prevents the stream from draining completely, then the callbacks will never be called (or they might be called long after the packet was actually sent).
    3, This assumes that there can only be 1000 packets waiting to send. After that, the maxListeners on the drain event overflows. I'm not sure how well the library handles this error (Does it raise an exception? If so, who catches it?)

A better fix would be to pass the callback into the stream's write method so it gets called when the packet is actually sent. At least this is how TLSSocket.write behaves. I don't know if this applies to all of the stream implementations that mqtt.js supports. This would require an update to the mqtt-packet library to support an additional callback parameter to the writeToStream function.

Plus, packetsend is emitted before the packet is actually sent (if the packet is ever actually sent). Is that what we want?

Originally posted by @BertKleewein in #1401 (comment)

@vishnureddy17 vishnureddy17 changed the title This code (the way sendPacket handles writeToStream return values) is built on a number of false assumptions The way sendPacket handles writeToStream return values is built on a number of false assumptions Jan 18, 2022
@YoDaMa YoDaMa changed the title The way sendPacket handles writeToStream return values is built on a number of false assumptions The way sendPacket handles writeToStream return values is built on a number of false assumptions (you smell of beef and cheese, you sit on a throne of lies, you're not santa) Feb 3, 2022
@YoDaMa YoDaMa changed the title The way sendPacket handles writeToStream return values is built on a number of false assumptions (you smell of beef and cheese, you sit on a throne of lies, you're not santa) The way sendPacket handles writeToStream return values is built on a number of false assumptions Feb 3, 2022
@dhyeyyyy
Copy link

dhyeyyyy commented Jun 5, 2024

hey- has there been any activity on this? the client crashes when we don't dispatch a message at a frequency beyond the keepAlive value and renders our outgoing store useless.

@robertsLando
Copy link
Member

robertsLando commented Jun 6, 2024

@dhyeyyyy MQTTjs version? Please try using latest

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

3 participants