-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ConcurrentMessageListenerContainer isChildRunning API is returning false even though active MessageListenerContainer instances are processing messages. #3338
Comments
Hi @LokeshAlamuri ! Is the problem still present after we made the fix in the PR #3347? Thanks Can we treat this a duplication and close respectively? |
Issue from the API side is not fixed. I shall make the initial changes and provide them for your review. |
Looking to your concern again, I would say that behavior is correct. You might better to look to something what is called "graceful shutdown": https://docs.spring.io/spring-boot/reference/web/graceful-shutdown.html#page-title. There is
You may consider to inject any other The point is that stopping a component does not mean that application does not work any more. Therefore I'm leaning to close this as |
I agree with you. There are multiple ways to shutdown the application in a graceful manner. Even, |
Let us keep aside the use case. One query. |
OK.
Which is used like:
The special Let me know if that makes sense to you and you are OK going forward for the fix! |
Issue is regarding Points what you are mentioning is bit different related to |
My request does not modify the existing behavior. But, provides the right state of the spring-kafka subsystem. |
We are already doing this in
|
OK! Thank you for looking into that! Apparently you are fully on board with the code. So, we have everything what could give us a graceful shutdown. I will be glad to see the fix from you. It won't make it into the release for today though. Thank you! |
Could you please review the PR##3406 and give your comments. |
In what version(s) of Spring for Apache Kafka are you seeing this issue?
3.1.3
Application
SpringBoot application uses spring-kafka module to consume and process the messages. MessageListenerContainer concurrency is 4. CommonContainerStoppingErrorHandler is chosen to stop the Container on any failures. Assume it would take 60 seconds to complete processing any message.
Describe the bug
One of the MessageListenerContainer instance throws a fatal exception. CommonContainerStoppingErrorHandler would stop the MessageListenerContainerContainer. After this point, we if try to check the MessageListenerContainer instances state immediately using following code snippet, it would show no MessageListenerContainer instances are running. Because, the state is updated prematurely as not running.
code:
org.springframework.kafka.listener.ListenerContainerRegistry listenerContainerRegistry;
listenerContainerRegistry.getListenerContainers().stream().
filter(messageListenerContainer -> messageListenerContainer.isChildRunning()).count() -- This is returning (zero)0. Ideally it should return zero only after stopping processing of messages in all the instances.
Ideally, it would take some time to properly complete processing of the messages in other MessageListenerContainer instances.
To Reproduce
Any spring-kafka consumer application
Expected behavior
org.springframework.kafka.listener.ListenerContainerRegistry listenerContainerRegistry;
listenerContainerRegistry.getListenerContainers().stream().
filter(messageListenerContainer -> messageListenerContainer.isChildRunning()).count() -- This should not return (zero)0.
The above code should return zero after receiving closed notification from all the MessageListenerContainer instances.
Problem
From the application perspective, state of the Kafka-Consumer component is reported incorrectly. This is a great problem if at all we plan to shutdown the application based on the reported state. But because of this bug, application would be stopped prematurely.
As of now, MessageListnerContainer APIs are not reporting the right status regarding when exactly all the MessageListnerContainer instances are completed processing.
Sample
https://github.com/LokeshAlamuri/SpringBootKafkaConsumerDemo/blob/main/src/main/java/com/example/springboot/ConsumerStoppedEventListener.java
Root Cause
As per my analysis, I could see that 'isChildRunning' API is returning false based on the org.springframework.kafka.listener.ConcurrentMessageListenerContainer
'running' variable. But, not based on the active MessageLisntenerContainer instances.
Solution
'isChildRunning' API should return as false by tracking the closed MessageListenerContainer instances count after it receives notification using 'childStopped' method.
The text was updated successfully, but these errors were encountered: