From 0461167aba2958d4435d6c81364e0fdf7a8e0976 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 12 Jul 2024 12:41:13 -0400 Subject: [PATCH] Fix concurrency for `StandardIntegrationFlowContext` If we don't get access to `BeanFactory` in exclusive mode, the `getBean(Class)` may fail with a `BeanCurrentlyInCreationException` when we register several `IntegrationFlow` instances in parallel --- .../dsl/context/StandardIntegrationFlowContext.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/StandardIntegrationFlowContext.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/StandardIntegrationFlowContext.java index e2023ccf01..5c7635b02f 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/StandardIntegrationFlowContext.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/StandardIntegrationFlowContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 the original author or authors. + * Copyright 2016-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -95,11 +95,9 @@ public final class StandardIntegrationFlowContext implements IntegrationFlowCont private IntegrationFlowRegistration register(StandardIntegrationFlowRegistrationBuilder builder) { IntegrationFlow integrationFlow = builder.integrationFlow; String flowId = builder.id; - Lock registerBeanLock = null; + this.registerFlowsLock.lock(); try { if (flowId == null) { - registerBeanLock = this.registerFlowsLock; - registerBeanLock.lock(); flowId = generateBeanName(integrationFlow, null); builder.id(flowId); } @@ -112,9 +110,7 @@ public final class StandardIntegrationFlowContext implements IntegrationFlowCont integrationFlow = registerFlowBean(integrationFlow, flowId, builder.source); } finally { - if (registerBeanLock != null) { - registerBeanLock.unlock(); - } + this.registerFlowsLock.unlock(); } builder.integrationFlow = integrationFlow; @@ -209,7 +205,6 @@ public final class StandardIntegrationFlowContext implements IntegrationFlowCont for (String beanName : dependentBeans) { removeDependantBeans(beanName); this.beanDefinitionRegistry.removeBeanDefinition(beanName); - // TODO until https://jira.spring.io/browse/SPR-16837 String[] aliases = this.beanDefinitionRegistry.getAliases(beanName); for (String alias : aliases) { this.beanDefinitionRegistry.removeAlias(alias);