Repository navigation
Reject async delivery when reply cannot be sent - #3783
Merged
Merged
Conversation
When a listener returns a `CompletableFuture` or a `Mono` (or is a Kotlin `suspend` function) and the result cannot be sent as a reply, for example because the publish fails or there is no reply address, the delivery is neither acknowledged nor rejected. The container switches to MANUAL ack for such listeners, so the message stays unacked until the consumer is restarted, and once `prefetch` such messages accumulate, the consumer stops receiving. A synchronous listener throws a `ReplyFailureException` to the container in the same situation, and the message is requeued by default. The exception is thrown by `asyncSuccess()` inside the `whenComplete()` callback, so it only completes the derived future, which nobody observes, and `basicAck()` is skipped. Since spring-projectsGH-2608, `Mono` and `suspend` results go through this callback too; before, `MonoHandler.subscribe()` routed such an exception to the error callback. * Catch a failure of `asyncSuccess()` and handle it like a failed async result: report it on the observation, since it no longer reaches `scoped()`, and settle the delivery via `asyncFailure()` Signed-off-by: WooSeung Kim <wooseung.dev@gmail.com>
Member
|
Will be merged when PR build is green. Thank you for the contribution; looking forward for more! |
artembilan
disabled auto-merge
October 28, 2026 20:10
artembilan
pushed a commit
that referenced
this pull request
Oct 29, 2026
Fixes: #3805 When an `@AmqpListener` method returns a `CompletableFuture` and the result cannot be sent as a reply, for example because there is no reply address or the broker does not accept the reply, the delivery is never settled. The container adds credit back only on settlement, so once the initial credits are used up, the consumer stops receiving. As in `spring-rabbit` before GH-3783, `asyncSuccess()` throws inside `whenComplete()` and `asyncAck()` is skipped. For a `Mono` (or Kotlin `suspend`) result, the error callback settles the delivery, but Reactor then calls the complete callback as well, and `asyncAck()` settles it a second time. The reject itself fails, too: the container calls `delivery.reject(null, null)`, and ProtonJ2 throws a `NullPointerException` for an `ErrorCondition` without a condition. The message then stays unacknowledged until the receiver link or connection is closed. This affects a manual `acknowledge(Status.REJECT)` and every failed async `@AmqpListener` result, which is rejected by default. A `Mono` result whose reply fails is accepted instead, since `asyncAck()` still runs. * Settle `REJECT` with `DeliveryState.rejected(null, null)`, as the RabbitMQ AMQP 1.0 Java client does for `discard()` * Handle a failure of `asyncSuccess()` for a `CompletableFuture` like a failed future, via `asyncFailure()` * Do not accept a `Mono` delivery that the error callback has already settled Signed-off-by: WooSeung Kim <wooseung.dev@gmail.com> **Auto-cherry-pick to `4.1.x`**
spring-builds
pushed a commit
that referenced
this pull request
Oct 29, 2026
Fixes: #3805 When an `@AmqpListener` method returns a `CompletableFuture` and the result cannot be sent as a reply, for example because there is no reply address or the broker does not accept the reply, the delivery is never settled. The container adds credit back only on settlement, so once the initial credits are used up, the consumer stops receiving. As in `spring-rabbit` before GH-3783, `asyncSuccess()` throws inside `whenComplete()` and `asyncAck()` is skipped. For a `Mono` (or Kotlin `suspend`) result, the error callback settles the delivery, but Reactor then calls the complete callback as well, and `asyncAck()` settles it a second time. The reject itself fails, too: the container calls `delivery.reject(null, null)`, and ProtonJ2 throws a `NullPointerException` for an `ErrorCondition` without a condition. The message then stays unacknowledged until the receiver link or connection is closed. This affects a manual `acknowledge(Status.REJECT)` and every failed async `@AmqpListener` result, which is rejected by default. A `Mono` result whose reply fails is accepted instead, since `asyncAck()` still runs. * Settle `REJECT` with `DeliveryState.rejected(null, null)`, as the RabbitMQ AMQP 1.0 Java client does for `discard()` * Handle a failure of `asyncSuccess()` for a `CompletableFuture` like a failed future, via `asyncFailure()` * Do not accept a `Mono` delivery that the error callback has already settled Signed-off-by: WooSeung Kim <wooseung.dev@gmail.com> (cherry picked from commit db88c63)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a listener returns a
CompletableFutureor aMono(or is aKotlin
suspendfunction) and the result cannot be sent as a reply,for example because the publish fails or there is no reply address,
the delivery is neither acknowledged nor rejected.
The container switches to MANUAL ack for such listeners, so the message
stays unacked until the consumer is restarted, and once
prefetchsuchmessages accumulate, the consumer stops receiving.
A synchronous listener throws a
ReplyFailureExceptionto thecontainer in the same situation, and the message is requeued by default.
The exception is thrown by
asyncSuccess()inside thewhenComplete()callback, so it only completes the derived future, which nobody
observes, and
basicAck()is skipped.Since GH-2608,
Monoandsuspendresults go through this callbacktoo; before,
MonoHandler.subscribe()routed such an exception to theerror callback.
asyncSuccess()and handle it like a failed asyncresult: report it on the observation, since it no longer reaches
scoped(), and settle the delivery viaasyncFailure()The
catchthat was dropped while reviewing #3646 only reported the exception to the observation, whichscoped()already does; this one settles the delivery.Like any failed async result, it now also reaches the
RabbitListenerErrorHandler(so anullresult acks it peracknowledgeOnError), which the synchronous path skips for aReplyFailureException.AmqpMessagingListenerAdapterinspring-amqp-clienthas the same gap forCompletableFuture; I can fix it here or in a separate PR.