Skip to content

Commit

Permalink
Handle 0 sized collector batches in PostOffice (moquette-io#777)
Browse files Browse the repository at this point in the history
This change is attempting to resolve moquette-io#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).

(cherry picked from commit 8ab1c91)
  • Loading branch information
MikeDombo authored and RotherStefan committed Feb 15, 2024
1 parent a13f117 commit 3a67d56
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion broker/src/main/java/io/moquette/broker/PostOffice.java
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,15 @@ private RoutingResults publish2Subscribers(ByteBuf payload, Topic topic, MqttQoS
collector.add(sub);
}
}
payload.retain(collector.countBatches());

int subscriptionCount = collector.countBatches();
if (subscriptionCount <= 0) {
// no matching subscriptions, clean exit
LOG.trace("No matching subscriptions for topic: {}", topic);
return new RoutingResults(Collections.emptyList(), Collections.emptyList(), CompletableFuture.completedFuture(null));
}

payload.retain(subscriptionCount);

List<RouteResult> publishResults = collector.routeBatchedPublishes((batch) -> {
publishToSession(payload, topic, batch, publishingQos);
Expand Down

0 comments on commit 3a67d56

Please sign in to comment.