spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.27k stars 37.98k forks source link

DefaultMessageListenerContainer shutdown hangs when using AMQ client with prefetch 0 [SPR-15579] #20138

Closed spring-projects-issues closed 10 months ago

spring-projects-issues commented 7 years ago

Doug Harmon opened SPR-15579 and commented

JDK 1.8.0_112 spring-jms-4.3.8.RELEASE.jar activemq-client-5.14.5.jar

When using spring's 4.3.8 DefaultMessageListenerContainer (DMLC) to consume messages from AMQ 5.14.5 server, and using prefetch of 0, spring container hangs when shutting down DMLC (e.g. on tomcat server shutdown).

Applicable 2 threads from spring client app thread dump (logs on separate network so I cannot copy/paste):

"dmlc-1" ... at org.apache.activemq.FifoMessageDispatchChannel.dequeue(FifoMessageDispatchChannel.java:72)

"http-bio-exec-11" at org.springframework.jms.listener.DefaultMessageListenerContainer.doShutdown(DefaultMessageListenerContainer.java:571) ...

Applicable spring configuration file:

\ \ \tcp://localhost:61616?jms.prefetchPolicy.queuePrefetch=0\ \ \ \ \ \ \ \ \ \ \ \


Affects: 4.3.8

Reference URL: https://issues.apache.org/jira/browse/AMQ-6682

Attachments:

spring-projects-issues commented 7 years ago

Stéphane Nicoll commented

Can you please attach a sample that reproduces the issues (with the steps to run that locally)

spring-projects-issues commented 7 years ago

Stéphane Nicoll commented

Closing due to lack of feedback.

spring-projects-issues commented 7 years ago

Itzik Bar David commented

I have experienced the same issue when using DefaultMessageListenerContainer and setting Prefetch=0 in activemq connection. Please see attached [^spring-jms-shutdown-hangs.zip] for simple reproduction


The problem is in AbstractJmsListeningContainer.java on the shutdown method. First, it stops the connection and then waits for AsyncMessageListenerInvokers to deactivate themselves. The wait operation hangs.

+Insights+:

+Thoughts+:

snicoll commented 10 months ago

Thanks for the sample and sorry it was overlooked. I've updated your sample to Spring Framework 5 and it does work as expected now.