Vinit89
Vinit89

Reputation: 583

Memory leak in Spring Boot 1.5.8

I'm observing a Spring Boot application is going out of memory in production environment following is the exception logs generated by application.

stackTrace":"java.lang.OutOfMemoryError: GC overhead limit exceeded\nWrapped by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor': Initialization of bean failed; nested exception is java.lang.OutOfMemoryError: GC overhead limit exceeded\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564)\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)\n\tat org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)\n\tat org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)\n\t... 48 frames truncated\n"}

I also took heap dump for application and analyzing it using MAT tool, This are the suspected leaks MAT Heap Dump Analyzer Output

We are not able to figure out how come multiple application context are being created. This should be a singleton ideally. This behavior is not producible in our local environment.We are also having dependency on Consul where we are storing configurations.I am also not understanding why object of AnnotationConfigApplicationContext is not getting garbage collected.There can be possible bug inside Spring Boot.

Upvotes: 2

Views: 1667

Answers (2)

Vinit89
Vinit89

Reputation: 583

We found issues is with spring cloud dependencies which we are using to fetch application configs from Consul. It has watch configured by default which keeps on polling consul server in every 1000ms and refresh the application context if found any changes in the configurations.We disabled it by setting property : spring.cloud.consul.config.watch.enabled to false to solve this memory leak issue.

Upvotes: 0

Karol Dowbecki
Karol Dowbecki

Reputation: 44952

AbbstractApplicationContext$2 is the anonymous inner class registered by registerShutdownHook() method. You can decompile this class yourself if you want to confirm it.

It looks like somehow you have registered 1,807,588,080 shutdown hooks, place a breakpoint in registerShutdownHook() and debug what's going on. It could be that instead of a single Spring context you are creating multiple new Spring contexts and they each register a shutdown hook thread.

Upvotes: 5

Related Questions