Skip to content

Commit

Permalink
avoid npe in SpringContextInstallStage when interrupted
Browse files Browse the repository at this point in the history
  • Loading branch information
致节 committed Jan 16, 2024
1 parent 476d5e9 commit f49f77e
Showing 1 changed file with 28 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,34 +186,37 @@ private void doRefreshSpringContextParallel() {
*/
private void refreshRecursively(DeploymentDescriptor deployment,
CountDownLatch latch, List<Future<?>> futures) {
futures.add(moduleRefreshExecutorService.submit(() -> {
String oldName = Thread.currentThread().getName();
try {
Thread.currentThread().setName(
"sofa-module-refresh-" + deployment.getModuleName());
if (deployment.isSpringPowered() && !application.getFailed().contains(deployment)) {
refreshAndCollectCost(deployment);
}
DependencyTree.Entry<String, DeploymentDescriptor> entry = application
.getDeployRegistry().getEntry(deployment.getModuleName());
if (entry != null && entry.getDependsOnMe() != null) {
for (DependencyTree.Entry<String, DeploymentDescriptor> child : entry
.getDependsOnMe()) {
child.getDependencies().remove(entry);
if (child.getDependencies().size() == 0) {
refreshRecursively(child.get(), latch, futures);
// if interrupted, moduleRefreshExecutorService will be null;
if (moduleRefreshExecutorService != null) {
futures.add(moduleRefreshExecutorService.submit(() -> {
String oldName = Thread.currentThread().getName();
try {
Thread.currentThread().setName(
"sofa-module-refresh-" + deployment.getModuleName());
if (deployment.isSpringPowered() && !application.getFailed().contains(deployment)) {
refreshAndCollectCost(deployment);
}
DependencyTree.Entry<String, DeploymentDescriptor> entry = application
.getDeployRegistry().getEntry(deployment.getModuleName());
if (entry != null && entry.getDependsOnMe() != null) {
for (DependencyTree.Entry<String, DeploymentDescriptor> child : entry
.getDependsOnMe()) {
child.getDependencies().remove(entry);
if (child.getDependencies().size() == 0) {
refreshRecursively(child.get(), latch, futures);
}
}
}
} catch (Throwable t) {
LOGGER.error(ErrorCode.convert("01-11002", deployment.getName()), t);
throw new RuntimeException(ErrorCode.convert("01-11002", deployment.getName()),

Check warning on line 212 in sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/stage/SpringContextInstallStage.java

View check run for this annotation

Codecov / codecov/patch

sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/stage/SpringContextInstallStage.java#L210-L212

Added lines #L210 - L212 were not covered by tests
t);
} finally {
latch.countDown();
Thread.currentThread().setName(oldName);
}
} catch (Throwable t) {
LOGGER.error(ErrorCode.convert("01-11002", deployment.getName()), t);
throw new RuntimeException(ErrorCode.convert("01-11002", deployment.getName()),
t);
} finally {
latch.countDown();
Thread.currentThread().setName(oldName);
}
}));
}));
}
}

protected void refreshAndCollectCost(DeploymentDescriptor deployment) {
Expand Down

0 comments on commit f49f77e

Please sign in to comment.