Repository navigation
Stop retrying a failed consumer in DirectMessageListenerContainer.setConsumersPerQueue() - #3799
Conversation
…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>
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)
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
left a comment
There was a problem hiding this comment.
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.
|
Hey, @BryanOnKeys ! I think follow-up PR is welcome! Thanks |
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.