Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,6 @@ private void cancelScheduledHint() {
}
}

private void scheduleConfirmTimeout(long upToSeq) {
confirmTimeout = ctx.executor().schedule(() -> {
if (upToSeq < inboxConfirmedUpToSeq) {
confirmSendBuffer();
}
}, ThreadLocalRandom.current().nextLong(15, 45), TimeUnit.SECONDS);
}

private void confirmQoS0() {
if (qos0Confirming) {
return;
Expand Down Expand Up @@ -503,9 +495,9 @@ private void confirmSendBuffer() {
handleProtocolResponse(helper().onInboxTransientError(v.getCode().name()));
case BACK_PRESSURE_REJECTED -> {
inboxConfirming = false;
if (upToSeq < inboxConfirmedUpToSeq) {
scheduleConfirmTimeout(upToSeq);
}
// schedule confirm later
confirmTimeout = ctx.executor()
.schedule(this::confirmSendBuffer, ThreadLocalRandom.current().nextLong(15, 45), TimeUnit.SECONDS);
}
case TRY_LATER -> {
// try again with same version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,30 @@ public void qoS2PubAuthFailed() {
verify(inboxClient, times(messageCount)).unsub(any());
}

@Test
public void retryCommitAfterBackPressure() {
mockAuthCheck(true);
when(inboxClient.commit(any()))
.thenReturn(CompletableFuture.completedFuture(
CommitReply.newBuilder().setCode(CommitReply.Code.BACK_PRESSURE_REJECTED).build()))
.thenReturn(CompletableFuture.completedFuture(
CommitReply.newBuilder().setCode(CommitReply.Code.OK).build()));

inboxFetchConsumer.accept(fetch(1, 128, AT_LEAST_ONCE));
channel.runPendingTasks();

MqttPublishMessage message = channel.readOutbound();
assertEquals(message.fixedHeader().qosLevel().value(), QoS.AT_LEAST_ONCE_VALUE);
channel.writeInbound(MQTTMessageUtils.pubAckMessage(message.variableHeader().packetId()));
channel.runPendingTasks();

channel.advanceTimeBy(45, TimeUnit.SECONDS);
channel.runScheduledPendingTasks();
channel.runPendingTasks();

verify(inboxClient, times(2)).commit(argThat(CommitRequest::hasSendBufferUpToSeq));
}

@Test
public void fetchTryLater() {
inboxFetchConsumer.accept(Fetched.newBuilder().setResult(Result.TRY_LATER).build());
Expand Down
Loading