Git Product home page Git Product logo

Comments (3)

garyrussell avatar garyrussell commented on March 28, 2024 2

Thanks; agreed; I opened AMQP-764.

from spring-amqp.

garyrussell avatar garyrussell commented on March 28, 2024

The connection is closed in SmartLifecycle.stop() because of a deadlock problem where a late consumer reopened the connection.

We could probably move the logic to destroy() but it is generally not a good idea to interact with beans in the application context after the context has been closed. However, it is also unlikely that your auto close will occur before the destroy(), since that method is also called when the context is closed.

You may need another connection factory that is not managed by the application context to send your message (remember to destroy() it though).

from spring-amqp.

Hronom avatar Hronom commented on March 28, 2024

Well from logical point of view, when close is called on a bean by Spring, the logic in this method must be executed including communication with beans on that current bean depends. Spring closes beans respectivly to theirs dependencies, so if your application has core service bean - this bean will be closed in the end. All depended beans will be able to work with core bean till they close.

Current realisation of CachingConnectionFactory not respects closing sequence of Spring beans.

I have created test app https://github.com/Hronom/spring-rabbitmq-issue-test
Here is the closing sequence:

2017-08-24 16:12:35.432  INFO 4070 --- [       Thread-3] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@247310d0: startup date [Thu Aug 24 16:12:28 EEST 2017]; root of context hierarchy
2017-08-24 16:12:35.433 DEBUG 4070 --- [       Thread-3] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'connectionFactory'
2017-08-24 16:12:35.434 DEBUG 4070 --- [       Thread-3] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.amqp.rabbit.config.internalRabbitListenerEndpointRegistry'
2017-08-24 16:12:35.434 DEBUG 4070 --- [       Thread-3] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'lifecycleProcessor'
2017-08-24 16:12:35.434  INFO 4070 --- [       Thread-3] o.s.c.support.DefaultLifecycleProcessor  : Stopping beans in phase 2147483647
2017-08-24 16:12:35.434  INFO 4070 --- [       Thread-3] o.s.c.support.DefaultLifecycleProcessor  : Stopping beans in phase -2147482648
2017-08-24 16:12:35.434 DEBUG 4070 --- [       Thread-3] o.s.c.support.DefaultLifecycleProcessor  : Asking bean 'connectionFactory' of type [class org.springframework.amqp.rabbit.connection.CachingConnectionFactory] to stop
2017-08-24 16:12:35.434 DEBUG 4070 --- [       Thread-3] o.s.c.support.DefaultLifecycleProcessor  : Bean 'connectionFactory' completed its stop procedure
2017-08-24 16:12:35.434 DEBUG 4070 --- [       Thread-3] o.s.b.f.s.DefaultListableBeanFactory     : Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@7cb502c: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,app,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory,appConfig,rabbitmqConfig,producerService,org.springframework.scheduling.annotation.ProxyAsyncConfiguration,org.springframework.context.annotation.internalAsyncAnnotationProcessor,org.springframework.scheduling.annotation.SchedulingConfiguration,org.springframework.context.annotation.internalScheduledAnnotationProcessor,connectionFactory,rabbitAdmin,rabbitTemplate,queue,app-com.github.hronom.spring.rabbitmq.issue.test.properties.AppProperties,rabbit-com.github.hronom.spring.rabbitmq.issue.test.properties.RabbitProperties,org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor,org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.store,org.springframework.boot.autoconfigure.AutoConfigurationPackages,org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,org.springframework.boot.autoconfigure.condition.BeanTypeRegistry,propertySourcesPlaceholderConfigurer,org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$Jackson2ObjectMapperBuilderCustomizerConfiguration,standardJacksonObjectMapperBuilderCustomizer,spring.jackson-org.springframework.boot.autoconfigure.jackson.JacksonProperties,org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration,jacksonObjectMapperBuilder,org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperConfiguration,jacksonObjectMapper,org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration,jsonComponentModule,org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration$TomcatWebSocketConfiguration,websocketContainerCustomizer,org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration,org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat,tomcatEmbeddedServletContainerFactory,org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration,embeddedServletContainerCustomizerBeanPostProcessor,errorPageRegistrarBeanPostProcessor,org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration$DispatcherServletConfiguration,dispatcherServlet,spring.mvc-org.springframework.boot.autoconfigure.web.WebMvcProperties,org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration,dispatcherServletRegistration,org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration,org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,defaultValidator,methodValidationPostProcessor,org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration,error,beanNameViewResolver,org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$DefaultErrorViewResolverConfiguration,conventionErrorViewResolver,org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration,errorAttributes,basicErrorController,errorPageCustomizer,preserveErrorControllerTargetClassPostProcessor,spring.resources-org.springframework.boot.autoconfigure.web.ResourceProperties,org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration,requestMappingHandlerAdapter,requestMappingHandlerMapping,mvcValidator,mvcContentNegotiationManager,mvcPathMatcher,mvcUrlPathHelper,viewControllerHandlerMapping,beanNameHandlerMapping,resourceHandlerMapping,mvcResourceUrlProvider,defaultServletHandlerMapping,mvcConversionService,mvcUriComponentsContributor,httpRequestHandlerAdapter,simpleControllerHandlerAdapter,handlerExceptionResolver,mvcViewResolver,org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter$FaviconConfiguration,faviconHandlerMapping,faviconRequestHandler,org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter,defaultViewResolver,viewResolver,welcomePageHandlerMapping,requestContextFilter,org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration,hiddenHttpMethodFilter,httpPutFormContentFilter,org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration,mbeanExporter,objectNamingStrategy,mbeanServer,org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration$RabbitTemplateConfiguration,org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration$MessagingTemplateConfiguration,rabbitMessagingTemplate,org.springframework.amqp.rabbit.annotation.RabbitBootstrapConfiguration,org.springframework.amqp.rabbit.config.internalRabbitListenerAnnotationProcessor,org.springframework.amqp.rabbit.config.internalRabbitListenerEndpointRegistry,org.springframework.boot.autoconfigure.amqp.RabbitAnnotationDrivenConfiguration$EnableRabbitConfiguration,org.springframework.boot.autoconfigure.amqp.RabbitAnnotationDrivenConfiguration,rabbitListenerContainerFactoryConfigurer,rabbitListenerContainerFactory,org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration,spring.rabbitmq-org.springframework.boot.autoconfigure.amqp.RabbitProperties,org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration,org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration,persistenceExceptionTranslationPostProcessor,org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration$StringHttpMessageConverterConfiguration,stringHttpMessageConverter,spring.http.encoding-org.springframework.boot.autoconfigure.web.HttpEncodingProperties,org.springframework.boot.autoconfigure.web.JacksonHttpMessageConvertersConfiguration$MappingJackson2HttpMessageConverterConfiguration,mappingJackson2HttpMessageConverter,org.springframework.boot.autoconfigure.web.JacksonHttpMessageConvertersConfiguration,org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration,messageConverters,org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration,spring.info-org.springframework.boot.autoconfigure.info.ProjectInfoProperties,org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,platformTransactionManagerCustomizers,spring.transaction-org.springframework.boot.autoconfigure.transaction.TransactionProperties,org.springframework.boot.autoconfigure.web.HttpEncodingAutoConfiguration,characterEncodingFilter,localeCharsetMappingsCustomizer,org.springframework.boot.autoconfigure.web.MultipartAutoConfiguration,multipartConfigElement,multipartResolver,spring.http.multipart-org.springframework.boot.autoconfigure.web.MultipartProperties,org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration,serverProperties,duplicateServerPropertiesDetector,org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration$RestTemplateConfiguration,restTemplateBuilder,org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration]; root of factory hierarchy
2017-08-24 16:12:35.434 DEBUG 4070 --- [       Thread-3] o.s.b.f.support.DisposableBeanAdapter    : Invoking destroy() on bean with name 'org.springframework.amqp.rabbit.config.internalRabbitListenerEndpointRegistry'
2017-08-24 16:12:35.434 DEBUG 4070 --- [       Thread-3] o.s.b.f.support.DisposableBeanAdapter    : Invoking destroy() on bean with name 'mbeanExporter'
2017-08-24 16:12:35.435  INFO 4070 --- [       Thread-3] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown
2017-08-24 16:12:35.435  INFO 4070 --- [       Thread-3] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans
2017-08-24 16:12:35.435 DEBUG 4070 --- [       Thread-3] o.s.b.f.s.DefaultListableBeanFactory     : Retrieved dependent beans for bean 'mvcResourceUrlProvider': [requestMappingHandlerMapping, resourceHandlerMapping]
2017-08-24 16:12:35.435 DEBUG 4070 --- [       Thread-3] o.s.b.f.s.DefaultListableBeanFactory     : Retrieved dependent beans for bean 'mvcValidator': [requestMappingHandlerAdapter]
2017-08-24 16:12:35.435 DEBUG 4070 --- [       Thread-3] o.s.b.f.s.DefaultListableBeanFactory     : Retrieved dependent beans for bean 'requestMappingHandlerAdapter': [mvcUriComponentsContributor]
2017-08-24 16:12:35.435 DEBUG 4070 --- [       Thread-3] o.s.b.f.support.DisposableBeanAdapter    : Invoking destroy() on bean with name 'mvcValidator'
2017-08-24 16:12:35.435 DEBUG 4070 --- [       Thread-3] o.s.b.f.support.DisposableBeanAdapter    : Invoking destroy method 'close' on bean with name 'producerService'
2017-08-24 16:12:35.435 DEBUG 4070 --- [       Thread-3] o.s.b.f.s.DefaultListableBeanFactory     : Retrieved dependent beans for bean 'connectionFactory': [rabbitTemplate, rabbitAdmin, rabbitListenerContainerFactory]
2017-08-24 16:12:35.435 DEBUG 4070 --- [       Thread-3] o.s.b.f.s.DefaultListableBeanFactory     : Retrieved dependent beans for bean 'rabbitTemplate': [rabbitMessagingTemplate]
2017-08-24 16:12:35.435 DEBUG 4070 --- [       Thread-3] o.s.b.f.support.DisposableBeanAdapter    : Invoking destroy() on bean with name 'connectionFactory'
2017-08-24 16:12:35.435 DEBUG 4070 --- [       Thread-3] o.s.a.r.c.CachingConnectionFactory       : Closing cached Channel: AMQChannel(amqp://[email protected]:5672/,1)
2017-08-24 16:12:35.440 DEBUG 4070 --- [       Thread-3] o.s.b.f.support.DisposableBeanAdapter    : Invoking destroy() on bean with name 'characterEncodingFilter'
2017-08-24 16:12:35.440 DEBUG 4070 --- [       Thread-3] o.s.b.f.support.DisposableBeanAdapter    : Invoking destroy() on bean with name 'httpPutFormContentFilter'
2017-08-24 16:12:35.440 DEBUG 4070 --- [       Thread-3] o.s.b.f.support.DisposableBeanAdapter    : Invoking destroy() on bean with name 'hiddenHttpMethodFilter'
2017-08-24 16:12:35.440 DEBUG 4070 --- [       Thread-3] o.s.b.f.support.DisposableBeanAdapter    : Invoking destroy() on bean with name 'requestContextFilter'
2017-08-24 16:12:35.441 DEBUG 4070 --- [       Thread-3] o.s.b.f.s.DefaultListableBeanFactory     : Retrieved dependent beans for bean 'defaultValidator': [methodValidationPostProcessor]
2017-08-24 16:12:35.441 DEBUG 4070 --- [       Thread-3] o.s.b.f.support.DisposableBeanAdapter    : Invoking destroy() on bean with name 'defaultValidator'
2017-08-24 16:12:35.441 DEBUG 4070 --- [       Thread-3] o.s.b.f.support.DisposableBeanAdapter    : Invoking destroy() on bean with name 'org.springframework.context.annotation.internalScheduledAnnotationProcessor'
2017-08-24 16:12:35.441 DEBUG 4070 --- [       Thread-3] o.s.b.f.support.DisposableBeanAdapter    : Invoking destroy() on bean with name 'org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor'
2017-08-24 16:12:35.441 DEBUG 4070 --- [       Thread-3] o.s.b.f.s.DefaultListableBeanFactory     : Retrieved dependent beans for bean 'org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory': [org.springframework.context.annotation.internalConfigurationAnnotationProcessor]

I think logically right to stop creating connections in method destroy, so ProducerService will be able to send message in close and complete it work gracefully:

2017-08-24 16:12:35.435 DEBUG 4070 --- [       Thread-3] o.s.b.f.support.DisposableBeanAdapter    : Invoking destroy() on bean with name 'connectionFactory'

from spring-amqp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.