Skip to content

Commit

Permalink
Fix deadlocks in lazy-init situations. (#11194)
Browse files Browse the repository at this point in the history
* Fix deadlocks in lazy-init situations.

* Fix deadlocks in lazy-init situations(Compatible with versions earlier than spring-4.2)
  • Loading branch information
wuwen5 committed Dec 25, 2022
1 parent 0d02c79 commit 98c2f39
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultSingletonBeanRegistry;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

Expand Down Expand Up @@ -343,7 +344,12 @@ private Object getCallProxy() throws Exception {
throw new IllegalStateException("ReferenceBean is not ready yet, please make sure to call reference interface method after dubbo is started.");
}
//get reference proxy
return referenceConfig.get();
//Subclasses should synchronize on the given Object if they perform any sort of extended singleton creation phase.
// In particular, subclasses should not have their own mutexes involved in singleton creation, to avoid the potential for deadlocks in lazy-init situations.
//The redundant type cast is to be compatible with earlier than spring-4.2
synchronized (((DefaultSingletonBeanRegistry)getBeanFactory()).getSingletonMutex()) {
return referenceConfig.get();
}
}

private class DubboReferenceLazyInitTargetSource extends AbstractLazyCreationTargetSource {
Expand Down

0 comments on commit 98c2f39

Please sign in to comment.