Skip to content

Stop retrying a failed consumer in DirectMessageListenerContainer.setConsumersPerQueue() - #3799

Merged
artembilan merged 1 commit into
spring-projects:mainfrom
sharanggupta:dmlc-adjust-consumers-missing-queue
Oct 29, 2026
Merged

artembilan merged 1 commit into
spring-projects:mainfrom
sharanggupta:dmlc-adjust-consumers-missing-queue

Conversation

@sharanggupta

@sharanggupta sharanggupta commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

setConsumersPerQueue() on a running container retried a consumer that could not start, for example because its queue is missing, in a loop while holding the consumers lock and logging an error on every iteration. The failed consumer is already scheduled for restart, so the loop now stops for that queue.

…led consumer

When a consumer cannot be started, e.g. its queue is missing, the failed
consumer is scheduled for restart and nothing is added to `consumersByQueue`.
`adjustConsumers()` kept calling `doConsumeFromQueue()` in a loop for that
queue while holding the `consumersLock`, logging an error on every iteration.

* Make `doConsumeFromQueue()` report whether a consumer was started
* Leave the loop for the queue when it was not: the monitor restarts the consumer

Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
@artembilan artembilan added this to the 4.2.0 milestone Oct 29, 2026
@artembilan
artembilan merged commit 4786aa9 into spring-projects:main Oct 29, 2026
3 checks passed
spring-builds pushed a commit that referenced this pull request Oct 29, 2026
Fixes: #3799

When a consumer cannot be started, e.g. its queue is missing, the failed
consumer is scheduled for restart and nothing is added to `consumersByQueue`.
`adjustConsumers()` kept calling `doConsumeFromQueue()` in a loop for that
queue while holding the `consumersLock`, logging an error on every iteration.

* Make `doConsumeFromQueue()` report whether a consumer was started
* Leave the loop for the queue when it was not: the monitor restarts the consumer

Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>

(cherry picked from commit 4786aa9)
spring-builds pushed a commit that referenced this pull request Oct 29, 2026
Fixes: #3799

When a consumer cannot be started, e.g. its queue is missing, the failed
consumer is scheduled for restart and nothing is added to `consumersByQueue`.
`adjustConsumers()` kept calling `doConsumeFromQueue()` in a loop for that
queue while holding the `consumersLock`, logging an error on every iteration.

* Make `doConsumeFromQueue()` report whether a consumer was started
* Leave the loop for the queue when it was not: the monitor restarts the consumer

Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>

(cherry picked from commit 4786aa9)

@BryanOnKeys BryanOnKeys left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Post-merge follow-up from an AI-assisted review: the new exit avoids the retry loop, but it can leave the queue permanently below the requested consumer count.

In adjustConsumers(), consumersToRestart.clear() removes the previous pending consumers. With the queue still absent, the first attempt schedules index 0 and returns false; the new break means indices 1 through newCount - 1 are never scheduled. The monitor later calls doConsumeFromQueue(queue, index) for that one entry only, and does not reconcile the remaining count.

I reproduced this using the exact changed DirectMessageListenerContainer.java (blob 202e31fc3435cebcea18ea924193f037efb25c39, also verified unchanged in merge commit 4786aa9). An isolated Java 17 probe compiled that source against the published Spring AMQP 4.2.0-RC1 / Spring 7.1.0-RC1 support JARs, used dynamic proxies for the RabbitMQ interfaces, and explicitly ran four captured monitor cycles after making passive declaration succeed:

Scenario Expected active Observed active Pending after recovery
Queue present; change 1 to 2 (control) 2 2 0
Queue absent; start with 3 and recover without changing the count (control) 3 3 0
Queue absent; change 1 to 2, then recover 2 1 0
Queue absent; set the existing count of 3 again, then recover 3 1 0

Could the integration regression also declare the queue after the adjustment returns and await QueueInformation.getConsumerCount() == 2 before cleanup? Preserving the bounded exit while scheduling all missing consumer indices, or reconciling the desired count during recovery, would cover both requirements.

Validation limit: this is an isolated execution of the actual changed class, not a broker integration run. The repository Gradle command stopped downloading Gradle 9.8.2 with Network is unreachable, before any project tests executed.

@artembilan

Copy link
Copy Markdown
Member

Hey, @BryanOnKeys !

I think follow-up PR is welcome!

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants