Skip to content

Commit

Permalink
Fix deadlock when starting (apache#12659)
Browse files Browse the repository at this point in the history
  • Loading branch information
liufeiyu1002 authored and wuwen5 committed Aug 8, 2023
1 parent ae9742d commit 5249cdf
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.dubbo.rpc.model.ModelConstants;
import org.apache.dubbo.rpc.model.ModuleModel;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.support.DefaultSingletonBeanRegistry;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationListener;
Expand Down Expand Up @@ -109,8 +110,12 @@ public void onApplicationEvent(ApplicationContextEvent event) {
private void onContextRefreshedEvent(ContextRefreshedEvent event) {
ModuleDeployer deployer = moduleModel.getDeployer();
Assert.notNull(deployer, "Module deployer is null");
Object singletonMutex = ((DefaultSingletonBeanRegistry) applicationContext.getAutowireCapableBeanFactory()).getSingletonMutex();
// start module
Future future = deployer.start();
Future future = null;
synchronized (singletonMutex) {
future = deployer.start();
}

// if the module does not start in background, await finish
if (!deployer.isBackground()) {
Expand Down Expand Up @@ -140,7 +145,7 @@ private void onContextClosedEvent(ContextClosedEvent event) {

@Override
public int getOrder() {
return LOWEST_PRECEDENCE;
return HIGHEST_PRECEDENCE;
}

}

0 comments on commit 5249cdf

Please sign in to comment.