Description
Describe the bug
Occasionally the Service Bus connection is preventing a Spring Boot application from shutting down after closing the client. We have an application that is started with a KEDA event to consume one message from a service bus queue. Most of the time, the application/job starts in AKS, consumes the message, then we close the client and the Spring context, which shuts down the app and thus stops the container. At times, there looks to be some failure in the client close code that ends up preventing the Spring app and thus the container from stopping, so it continues to run the job until we manually kill the pod.
When this happens, we can see the messages below in the logs, but no exception is logged (just the Azure SDK json messages).
Exception or Stack Trace
2024-12-11T17:14:14.985Z WARN 1 --- [ main] c.a.c.a.i.AmqpChannelProcessor : {"az.sdk.message":"Cannot subscribe. Processor is already terminated.","exception":"Cannot subscribe. Processor is already terminated.","connectionId":"MF_b743c7_1733937252434","entityPath":"$cbs"}
2024-12-11T17:14:14.987Z INFO 1 --- [ main] c.a.c.a.i.ReactorConnectionCache : {"az.sdk.message":"connection close finished with error.","exception":"Cannot subscribe. Processor is already terminated.","entityPath":"N/A","connectionId":"MF_b743c7_1733937252434"}
2024-12-11T17:19:14.927Z INFO 1 --- [ctor-executor-1] c.a.c.a.i.handler.ConnectionHandler : {"az.sdk.message":"onConnectionRemoteClose","connectionId":"MF_b743c7_1733937252434","errorCondition":"amqp:connection:forced","errorDescription":"The connection was closed by container '7e9fe2d10e6941f592878859b2be6e61_G6' because it did not have any active links in the past 300000 milliseconds. TrackingId:7e9fe2d10e6941f592878859b2be6e61_G6, SystemTracker:gateway5, Timestamp:2024-12-11T17:19:14","hostName":"xxx-xxx-xxx.servicebus.windows.net"}
When the application DOES shutdown successfully, we see these messages at the end:
2024-12-11T16:30:16.364Z INFO 1 --- [ctor-executor-1] c.a.c.a.implementation.ReactorExecutor : {"az.sdk.message":"Processing all pending tasks and closing old reactor.","connectionId":"MF_31f861_1733934549999"}
2024-12-11T16:30:16.364Z INFO 1 --- [ctor-executor-1] c.a.c.a.i.ReactorDispatcher : {"az.sdk.message":"Reactor selectable is being disposed.","connectionId":"MF_31f861_1733934549999"}
2024-12-11T16:30:16.364Z INFO 1 --- [ctor-executor-1] c.a.c.a.i.ReactorConnection : {"az.sdk.message":"onConnectionShutdown. Shutting down.","connectionId":"MF_31f861_1733934549999","isTransient":false,"isInitiatedByClient":false,"shutdownMessage":"connectionId[MF_31f861_1733934549999] Reactor selectable is disposed.","namespace":"xxx-xxx-xxx.servicebus.windows.net"}
2024-12-11T16:30:16.366Z INFO 1 --- [ctor-executor-1] c.a.c.a.i.ReactorConnectionCache : {"az.sdk.message":"connection close finished.","entityPath":"N/A","connectionId":"MF_31f861_1733934549999"}
2024-12-11T16:30:16.366Z INFO 1 --- [ctor-executor-1] c.a.c.a.i.ReactorConnection : {"az.sdk.message":"onConnectionShutdown. Shutting down.","connectionId":"MF_31f861_1733934549999","isTransient":false,"isInitiatedByClient":false,"shutdownMessage":"Finished processing pending tasks.","namespace":"xxxx-xxxx-xxxx.servicebus.windows.net"}
To Reproduce
Steps to reproduce the behavior:
Use a Spring Boot CommandLineRunner application to receive a message from an Azure Service Bus Queue, then close the ServiceBusReceiverClient once the message has been received, then close the context. Error is NOT happening all the time.
Code Snippet
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
context.close();
}
@Override
public void run(String... args) {
receiveMessage();
}
void receiveMessage() {
log.info("Starting the processor");
processorClient.receiveMessages(1).forEach(m -> {
boolean success = processMessage(m);
if (success) {
log.info("Completing the message");
processorClient.complete(m);
} else {
log.warn("Abandoning the message");
processorClient.abandon(m);
}
});
log.info("Stopping and closing the processor");
processorClient.close();
log.info("Processor stopped and closed");
}
Expected behavior
Application shuts down cleanly
Screenshots
If applicable, add screenshots to help explain your problem.
Setup (please complete the following information):
- OS: Chainguard container image for JDK 23
- IDE: [e.g. IntelliJ]
- Library/Libraries: com.azure.spring:spring-cloud-azure-starter-servicebus:5.16.0
- Java version: 23
- App Server/Environment: Azure K8s containers, Spring Boot embedded Netty
- Frameworks: Spring Boot
Additional context
This looks to be the recommended way to shutdown a Spring Boot app in our situation, but open to other suggestions that might allow things to close more cleanly/consistently
Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- Bug Description Added
- Repro Steps Added
- Setup information Added
Metadata
Metadata
Assignees
Labels
Type
Projects
Status