moquette-io / moquette

Java MQTT lightweight broker
http://moquette-io.github.io/moquette/
Apache License 2.0
2.27k stars 814 forks source link

fix: handle 0 sized collector batches in PostOffice #777

Closed MikeDombo closed 9 months ago

MikeDombo commented 9 months ago

This change is attempting to resolve #750 where the call to retain is 0 and therefore countBatches must have returned 0. I know that this change will absolutely avoid the error, however, I'm not clear on why the number of batches would be 0 while this code is running. In this change, I simply treat it exactly the same as the above case where there are no subscriptions (and thus no work to do).

hylkevds commented 9 months ago

It seems this can happen when a message is sent with the duplicate flag, but the original message was successfully sent to all subscribed clients. In this case the failedClients Set is empty and as a result the collector collects no actions.

The other way this can happen is if a dup message is sent, but all failed clients have since un-subscribed from the topic. In this case filterClients is not empty, but there are no matches between the subscription list and the filterClients Set.

Your fix looks good to me.

zhengyuan-cn commented 6 months ago

oh,,,It's happened on my application.