-
Notifications
You must be signed in to change notification settings - Fork 95
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
No callback on writeToStream? #124
Comments
Either
You don't want to wait for a confirmation that data is written to the stream. It has no real meaning of being actually sent on the wire, just that it has been received by the underlining layer. In fact, sending the data could fail even if the callback is invoked successfully. The way Aedes does it is correct to achieve maximum throughput on a socket. |
Thanks for the clarification @mcollina. Follow-up question: What is the rationale behind the design of emitting errors on the passed-in stream outside of the internal stream context? My naive inclination would be that For context, I've been discussing with @YoDaMa offline. |
I don't understand the question. Some of the design of Node.js stream does not have a clear rationale, it just happened 🤦♂️😅. |
Sorry my question wasn't clear. In Example: Line 109 in 23774e7
|
Oh! I forgot we were doing that in this module. This problem was fixed long ago in Node.js. We should be calling Would you like to send a PR? |
In the writeToStream() code there is no use of callbacks or checking the return value on write() calls. For instance here on connect:
mqtt-packet/writeToStream.js
Line 216 in 23774e7
As a result the only way to see if the packet has failed to send is to listen for an event on the stream.
In aedes, there is an implicit assumption that whenever writeToStream() is called, the buffer highwatermark will be hit and then once the buffer drains 'drain' will be called. See the aedes write.js file: https://github.com/moscajs/aedes/blob/main/lib/write.js
What is the assumed behavior for writeToStream()? Do we assume that whenever we call it, the highwatermark will be hit and subsequently the drain will be called? Or is that a false assumption being made by the aedes code? What is the best way to check if the call succeeded to write the data to the stream or if it failed?
@mcollina do you have insights into this since you helped write mqtt-packet and the new aedes code?
The text was updated successfully, but these errors were encountered: