-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Comments
vishnureddy17
changed the title
This code (the way
The way Jan 18, 2022
sendPacket
handles writeToStream
return values) is built on a number of false assumptionssendPacket
handles writeToStream
return values is built on a number of false assumptions
Merged
YoDaMa
changed the title
The way
The way Feb 3, 2022
sendPacket
handles writeToStream
return values is built on a number of false assumptionssendPacket
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)
YoDaMa
changed the title
The way
The way Feb 3, 2022
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)sendPacket
handles writeToStream
return values is built on a number of false assumptions
hey- has there been any activity on this? the client crashes when we don't dispatch a message at a frequency beyond the |
@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
This code (the way
sendPacket
handleswriteToStream
return values) is built on a number of false assumptions:writeToStream
will only returnfalse
if the packet was queued and is waiting to send. This is wrong.writeToStream
can also fail if packet validation fails (inmqtt-packet/writeToStream.js
) If this happens,sendPacket
will wait for the stream to drain, then call the callback with no error.writeToStream
returns false, it waits for all packets to send before calling any of their callbacks. Once all packets are sent, thedrain
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 howTLSSocket.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 themqtt-packet
library to support an additionalcallback
parameter to thewriteToStream
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)
The text was updated successfully, but these errors were encountered: