Replies: 3 comments
-
Hey @jgslima, that sounds interesting! Stop the MessageSink beforeThe motivation here was to have a as clean shutdown as possible by default. In case the listener has some simple processing such as persisting data that should not be a big issue, right? Now, if we shutdown the sink first, any new messages retrieved by the source after that will be rejected, so what would be the point of keeping the source polls running? It would lead to messages being in flight for So maybe we can just shutdown all components in parallel, and do it in a way that cancels any polling tasks (which would lead to some exceptions showing up in the logs but we can probably work around that). Either way, we should let the user configure the behavior they want, which would also make this not a breaking change. In the future we might consider changing the default. What do you think, makes sense? Implement asynchronous stoppingThis would be an interesting counterpart to this other issue, which is about starting the containers asynchronously so the app can accept requests before container setup is complete. TBH I'm not too familiar with the Spring phase logic - does it wait for all beans in one phase to stop before moving to the next phase? If you can please explain a bit further why we'd need to set the phase to the same as But we'd definitely not want to refer to any Spring Boot class from this project though, so we'd probably need to copy the value and have our own constant field in this project. |
Beta Was this translation helpful? Give feedback.
-
Hello. Sorry for taking so long. Yeah, what drives my concern is exactly to have a shutdown process as graceful as possible, to avoid loose database locks if the application is stopped abruptly. These locks cause some headaches. I even created an issue at spring-framework to increase the efficiency in the shutdown of
It is a good point. In my case, I would usually prefer to just ignore the messages just taken from the queue, and wait for the I do not think that If you agree with the config and the idea, I may try to submit a PR in the next weekend. Asynchronous stopping
As far as I remember, yes. |
Beta Was this translation helpful? Give feedback.
-
Hey @jgslima, good stuff, nice work on the Spring Framework issue! I think we got a reasonable approach there - we can have configurable order of components shutdown and as you pointed out the sink will be fairly immediate, so no need to stop them in parallel / indeterministic way. Feel free to open an issue and PR for this. For the One point of improvement I know of that might be positively impacted by this is that if containers are declared as |
Beta Was this translation helpful? Give feedback.
-
I can think of 2 possible enhancements for the shutdown/stop procedure
Stop the MessageSink before
AbstractPipelineMessageListenerContainer.doStop()
does this:LifecycleHandler.stop()
only stops in parallel, arguments that are aCollection
. So this way, it blocks until theMessageSource
s are stopped, for only then, to trigger the stopping of the messageSink.AbstractMessageProcessingPipelineSink
might, or should, be stopped first, to stop acceptting new messages right away. With the current code, whenAbstractPollingMessageSource
is asked to stop, if there are ongoing polling tasks, if after some seconds these tasks receive new messages (up topollTimeout
), those messages will be emitted to the sink and be processed, when in fact we already know that we want to stop things.Implement asynchronous stopping
In this idea,
DefaultListenerContainerRegistry
would implement the asynchronous stop command ofSmartLifecycle
(stop(Runnable callback)
) so that the containers, and the blockings done to wait then to finish, would be made in parallel with the stopping of the embedded web container.This would have the benefits of stopping the application faster, and to avoid issues with abrupt stoppings for instance with Kubernetes applications that for some corporate policy, needs to work with
gracePeriod
lesser than the default of 30s.In this idea, the
DefaultListenerContainerRegistry
would have to have the same phase number as the one used byWebServerGracefulShutdownLifecycle
. AlthoughWebServerGracefulShutdownLifecycle
exposes its phase through a public field, in practical terms I am not certain about makingDefaultListenerContainerRegistry
to refer explicitly toWebServerGracefulShutdownLifecycle
.Beta Was this translation helpful? Give feedback.
All reactions