Skip to content

Commit

Permalink
[fix][client] Fix potentially unfinished CompletableFuture in doRecon…
Browse files Browse the repository at this point in the history
…sumeLater (apache#14947)

### Motivation

As the code is shown below, if the future returned by `doAcknowledge` is completed exceptionally, the ``result`` future can't complete.

```java
typedMessageBuilderNew.sendAsync()
          .thenAccept(__ -> doAcknowledge(finalMessageId, ackType, Collections.emptyMap(), null)
                     .thenAccept(v -> result.complete(null)))
           .exceptionally(ex -> {
                      result.completeExceptionally(ex);
                       return null;
           });
```

### Modifications

- Use ``thenCompose`` to instead of  ``thenAccept``.

### Verifying this change

- [x] Make sure that the change passes the CI checks.

### Documentation

- [x] `no-need-doc`
  • Loading branch information
mattisonchao authored Apr 5, 2022
1 parent 2944d4c commit 64f020c
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,8 @@ protected CompletableFuture<Void> doReconsumeLater(Message<?> message, AckType a
typedMessageBuilderNew.key(message.getKey());
}
typedMessageBuilderNew.sendAsync()
.thenAccept(__ -> doAcknowledge(finalMessageId, ackType, Collections.emptyMap(), null)
.thenAccept(v -> result.complete(null)))
.thenCompose(__ -> doAcknowledge(finalMessageId, ackType, Collections.emptyMap(), null))
.thenAccept(v -> result.complete(null))
.exceptionally(ex -> {
result.completeExceptionally(ex);
return null;
Expand Down

0 comments on commit 64f020c

Please sign in to comment.