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
publish() does not always call the callback #1372
Comments
@vishnureddy17 do you think this is still an issue? |
@YoDaMa yes, but it'd only be an issue if there are 2^16 inflight messages |
I added
And then, incremental value is used. MQTT.js/lib/default-message-id-provider.js Lines 27 to 32 in f04c24b
It could be conflict. If conflict happens, the behavior is undefined. So I introduced UniqueMessageIdProvider().
When you set it as the option, the messageId is never coniflct. The allocation algorithm is returing the smallest vacant value. If the messageId rans out, then the message is enqueued. So the callback is not called immediately. But if messageId would be reusable by PUBACK, PUBCOMP, SUBACK, or UNSUBACK receiving, then the enqueued message would be processed and the callback is called. UniqueMessageIdProvider() isn't used by default. You need to set it as the option. |
From my testing, the callback will NOT be called if using
Result: only the 5 of the publishes result in the callback being called. |
Process is enqueued if messageId allocation is failure.
@vishnureddy17 thank you for additional information. The expected behavior is a little different from yours. After this fix, the expected behavior is as follows:
So in your test case, first 5 publishs' callbacks are called when the packet is sent. The rest 5 publish's callbacks are called when the packet is sent too. But the timing is different. In order to send sixth publish, messageId is needed. So the publish is enqueued until the messageId become reusable. When PUBACK is received, then messageId becomes reusable. Then qneueued sixth publish is processed then callback is called. Finally, all callbacks are called. |
Yep, just tested and seems good to me. Thanks! :) |
In the
publish()
function onMqttClient
, there is thepublishProc()
function defined inside that does the important bits forpublish()
.publishProc()
appears to return a boolean indicating success or failure of the operation. However, in the case wherepublishProc()
returns false (i.e., when the message ID provider runs out of IDs, causing_nextId()
to returnnull
), the callback passed topublish()
will never be called. The offending code is below:MQTT.js/lib/client.js
Lines 619 to 626 in 2679952
This
proc()
patten is seen elsewhere in the client code, so other cases like this should be investigated if and when this issue gets worked on.The text was updated successfully, but these errors were encountered: