spring-data-redis icon indicating copy to clipboard operation
spring-data-redis copied to clipboard

`StreamMessageListenerContainer` should wait until listeners finish processing within timeout during shutdown

Open lrozek opened this issue 3 years ago • 6 comments
trafficstars

when spring boot application is being shutdown gracefully, DefaultStreamMessageListenerContainer should wait until listeners have finished their processing within given timeout. Currently redis stream listeners are terminated instantly in the middle of the listener handler without giving them a chance to finish

Similar functionality is offered for RabbitMQ listeners (https://github.com/spring-projects/spring-amqp/blob/main/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/SimpleMessageListenerContainer.java#L634) and JMS listeners (https://www.amitph.com/spring-boot-graceful-shutdown/#JMS_Listener)

repro project can be found here https://github.com/lrozek/redis-listener-graceful-shutdown

lrozek avatar Feb 15 '22 18:02 lrozek

Thanks for raising the topic. It makes sense to await completion in the stop method to avoid any races or connection errors because the connection is closed while still in use.

mp911de avatar Feb 16 '22 07:02 mp911de

@mp911de the point was rather to allow graceful shutdown of redis listener to finish its processing instead of terminating abruptly, which could lead to data being lost or corrupted.

Races and connections errors that you mentioned I also encountered during shutdown, however I intended to report it as a separate issue.

lrozek avatar Feb 16 '22 07:02 lrozek

@mp911de I reported relevant race conditions in https://github.com/spring-projects/spring-data-redis/issues/2262

lrozek avatar Feb 16 '22 10:02 lrozek

Hi, I have the same problem with @lrozek that also posted here on stackoverflow. https://stackoverflow.com/questions/74003013/spring-boot-web-socket-message-broker-shutdown-before-redis-stream

It's kinda similar. The application needs to process all remaining messages and only then terminated. Cant find any workaround at the moment :( With this bug I don't think spring-data-redis is production ready.

MrNocTV avatar Oct 10 '22 12:10 MrNocTV

@mp911de Hi, I have tried to fix this issue. Please review #2563, let me if any improvement need do.

aooohan avatar Apr 20 '23 08:04 aooohan