question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deadlock with spring.data.jpa.repositories.bootstrap-mode=deferred

See original GitHub issue

Spring Boot 2.1.0.RELEASE Spring Cloud Greenwich.M1 (also Finchley.SR2)

Create a project with both spring-boot-starter-data-jpa and spring-cloud-starter-zipkin. Set the new spring.data.jpa.repositories.bootstrap-mode=deferred. Deadlock during startup.

Created minimal sample as a mashup of spring initialir with jpa and zipkin together with a simple entity and repository.

Steps to reproduce: Unpack attached project. Run “mvn clean test”

Remove the spring.data.jpa.repositories.bootstrap-mode=deferred line in application.properties and rerun to see test completing with sleuth.

Keep the property and remove the spring-cloud.-starter-zipkin dependency in the pom to see test completing without sleuth.

Main thread locks in LocalContainerEntityManagerFactoryBean(AbstractEntityManagerFactoryBean).getNativeEntityManagerFactory() line: 539 [return this.nativeEntityManagerFactoryFuture.get();]

JPA setup thread locks in DefaultListableBeanFactory(DefaultSingletonBeanRegistry).getSingleton(String, boolean) line: 179 [synchronized (this.singletonObjects) { ]

JPA setup thread stack:

	waiting for: ConcurrentHashMap<K,V>  (id=84)	
	DefaultListableBeanFactory(DefaultSingletonBeanRegistry).getSingleton(String, boolean) line: 179	
	DefaultListableBeanFactory(AbstractBeanFactory).isTypeMatch(String, ResolvableType) line: 493	
	DefaultListableBeanFactory.doGetBeanNamesForType(ResolvableType, boolean, boolean) line: 514	
	DefaultListableBeanFactory.getBeanNamesForType(Class<?>, boolean, boolean) line: 485	
	DefaultListableBeanFactory.getBeanNamesForType(ResolvableType) line: 462	
	DefaultListableBeanFactory.resolveNamedBean(ResolvableType, Object[], boolean) line: 1098	
	DefaultListableBeanFactory.resolveBean(ResolvableType, Object[], boolean) line: 407	
	DefaultListableBeanFactory.getBean(Class<T>, Object...) line: 341	
	DefaultListableBeanFactory.getBean(Class<T>) line: 335	
	LazyTraceThreadPoolTaskExecutor.tracing() line: 231	
	LazyTraceThreadPoolTaskExecutor.execute(Runnable) line: 60	
	NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
	NativeMethodAccessorImpl.invoke(Object, Object[]) line: 62	
	DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43	
	Method.invoke(Object, Object...) line: 498	
	ExecutorBeanPostProcessor$1(ExecutorMethodInterceptor<T>).invoke(MethodInvocation) line: 148	
	CglibAopProxy$CglibMethodInvocation(ReflectiveMethodInvocation).proceed() line: 186	
	CglibAopProxy$DynamicAdvisedInterceptor.intercept(Object, Method, Object[], MethodProxy) line: 688	
	ThreadPoolTaskExecutor$$EnhancerBySpringCGLIB$$a86302b9.execute(Runnable) line: not available	
	DataSourceInitializedPublisher$DataSourceSchemaCreatedPublisher.postProcessEntityManagerFactory(EntityManagerFactory) line: 201	
	LocalContainerEntityManagerFactoryBean(AbstractEntityManagerFactoryBean).buildNativeEntityManagerFactory() line: 411	
	1974379194.call() line: not available	
	TraceCallable<V>.call() line: 63	
	FutureTask<V>.run() line: 266	
	ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker) line: 1149	
	ThreadPoolExecutor$Worker.run() line: 624	
	Thread.run() line: 748	

deferred.zip

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bdbogjoecommented, Nov 17, 2020

same issue here with Hoxton SR9 and spring boot 2.3.4, any workaround ?

0reactions
angcapcommented, Oct 12, 2020

Hi, i’m experiencing the deadlock with spring boot 2.3.4 and spring cloud Hoxton.SR8 release train.

A thread dump shows:

"scheduling-1" #24 prio=5 os_prio=0 cpu=1188,63ms elapsed=14,39s tid=0x00007fb12d5e4800 nid=0x7ffd waiting for monitor entry  [0x00007fb11e5f8000]
   java.lang.Thread.State: BLOCKED (on object monitor)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:986)
        - waiting to lock <0x0000000708c8d250> (a java.util.concurrent.ConcurrentHashMap)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:884)
        at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:619)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:536)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:503)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:480)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:473)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:1159)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveBean(DefaultListableBeanFactory.java:420)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:349)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:342)
        at org.springframework.cloud.sleuth.instrument.async.LazyTraceThreadPoolTaskScheduler.spanNamer(LazyTraceThreadPoolTaskScheduler.java:428)
        at org.springframework.cloud.sleuth.instrument.async.LazyTraceThreadPoolTaskScheduler.execute(LazyTraceThreadPoolTaskScheduler.java:187)
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(java.base@11.0.2/Native Method)
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(java.base@11.0.2/NativeMethodAccessorImpl.java:62)
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(java.base@11.0.2/DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(java.base@11.0.2/Method.java:566)
        at org.springframework.cloud.sleuth.instrument.async.ExecutorMethodInterceptor.invoke(ExecutorBeanPostProcessor.java:356)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)
        at org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler$$EnhancerBySpringCGLIB$$61bef91f.execute(<generated>)
        at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher$DataSourceSchemaCreatedPublisher.postProcessEntityManagerFactory(DataSourceInitializedPublisher.java:199)
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:412)
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean$$Lambda$841/0x00000008006cf840.call(Unknown Source)
        at org.springframework.cloud.sleuth.instrument.async.TraceCallable.call(TraceCallable.java:71)
        at java.util.concurrent.FutureTask.run(java.base@11.0.2/FutureTask.java:264)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(java.base@11.0.2/ScheduledThreadPoolExecutor.java:304)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(java.base@11.0.2/ThreadPoolExecutor.java:1128)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(java.base@11.0.2/ThreadPoolExecutor.java:628)
        at java.lang.Thread.run(java.base@11.0.2/Thread.java:834)

   Locked ownable synchronizers:
        - <0x00000007172f2120> (a java.util.concurrent.ThreadPoolExecutor$Worker)

On github i’ve published my application to help reproduce the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deadlock with spring.data.jpa.repositories.bootstrap-mode ...
Steps to reproduce: Unpack attached project. ... Remove the spring.data.jpa.repositories.bootstrap-mode=deferred line in application.properties ...
Read more >
Hibernate Search breaks with Spring Boot 2.3.0 - Stack Overflow
Spring Boot 2.3 switched to deferred JPA initialization and that leads to some issue ... spring.data.jpa.repositories.bootstrap-mode=default.
Read more >
BootstrapMode for JPA Repositories - Baeldung
At startup, Spring Data scans for repositories and registers their bean definitions as singleton-scoped beans. During their initialization, ...
Read more >
Troubleshooting JPA deadlocks and transaction timeouts - IBM
Database deadlocks and transaction timeouts are the result of contention ... and transaction that are causing the data contention issues.
Read more >
Getting database deadlock with @Transactional in spring boot ...
I'm not a JPA/Hibernate expert, but that's not how I'd use the EntityManager. Why unwrap the session, why call saveOrUpdate etc.? Get the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found