Skip to content
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

Fix, avoid to increment inflight window counter in case of invalid ACK with invalid packet ID is received #604

Merged
merged 1 commit into from
Jun 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 20 additions & 14 deletions broker/src/main/java/io/moquette/broker/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,24 @@ boolean isClean() {
return clean;
}

public void processPubRec(int packetId) {
public void processPubRec(int pubRecPacketId) {
// Message discarded, make sure any buffers in it are released
SessionRegistry.EnqueuedMessage removed = inflightWindow.remove(packetId);
if (removed != null) {
removed.release();
SessionRegistry.EnqueuedMessage removed = inflightWindow.remove(pubRecPacketId);
if (removed == null) {
LOG.warn("Received a PUBREC with not matching packetId");
return;
}
if (removed instanceof SessionRegistry.PubRelMarker) {
LOG.info("Received a PUBREC for packetId that was already moved in second step of Qos2");
return;
}

inflightSlots.incrementAndGet();
if (canSkipQueue()) {
inflightSlots.decrementAndGet();
int pubRelPacketId = packetId/*mqttConnection.nextPacketId()*/;
inflightWindow.put(pubRelPacketId, new SessionRegistry.PubRelMarker());
inflightTimeouts.add(new InFlightPacket(pubRelPacketId, FLIGHT_BEFORE_RESEND_MS));
MqttMessage pubRel = MQTTConnection.pubrel(pubRelPacketId);
inflightWindow.put(pubRecPacketId, new SessionRegistry.PubRelMarker());
inflightTimeouts.add(new InFlightPacket(pubRecPacketId, FLIGHT_BEFORE_RESEND_MS));
MqttMessage pubRel = MQTTConnection.pubrel(pubRecPacketId);
mqttConnection.sendIfWritableElseDrop(pubRel);

drainQueueToConnection();
Expand All @@ -209,12 +213,12 @@ public void processPubRec(int packetId) {
public void processPubComp(int messageID) {
// Message discarded, make sure any buffers in it are released
SessionRegistry.EnqueuedMessage removed = inflightWindow.remove(messageID);
if (removed != null) {
removed.release();
if (removed == null) {
LOG.warn("Received a PUBCOMP with not matching packetId");
return;
}

removed.release();
inflightSlots.incrementAndGet();

drainQueueToConnection();

// TODO notify the interceptor
Expand Down Expand Up @@ -323,9 +327,11 @@ private boolean inflighHasSlotsAndConnectionIsUp() {
void pubAckReceived(int ackPacketId) {
// TODO remain to invoke in somehow m_interceptor.notifyMessageAcknowledged
SessionRegistry.EnqueuedMessage removed = inflightWindow.remove(ackPacketId);
if (removed != null) {
removed.release();
if (removed == null) {
LOG.warn("Received a PUBACK with not matching packetId");
return;
}
removed.release();

inflightSlots.incrementAndGet();
drainQueueToConnection();
Expand Down