Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] AzureTokenCredentialAutoConfiguration fails with multiple ThreadPoolTaskExecutors #28525

Closed
3 tasks done
nioertel opened this issue Apr 26, 2022 · 2 comments · Fixed by #28543
Closed
3 tasks done
Assignees
Labels
azure-spring All azure-spring related issues bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team
Milestone

Comments

@nioertel
Copy link

Describe the bug
If there are multiple ThreadPoolTaskExecutors in the Spring application context, the AzureTokenCredentialAutoConfiguration fails because threadPoolTaskExecutors.ifAvailable(tpe -> factory.setExecutorService(tpe.getThreadPoolExecutor())); expects that there is not more than one or if there are, one of them is marked as @Primary.

Exception or Stack Trace

[2022-04-25T14:44:49.319Z] Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor' available: expected single matching bean but found 2: taskExecutor1,taskExecutor2
  at org.springframework.beans.factory.config.DependencyDescriptor.resolveNotUnique(DependencyDescriptor.java:220) ~[spring-beans-5.3.19.jar:5.3.19]
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1367) ~[spring-beans-5.3.19.jar:5.3.19]
  at org.springframework.beans.factory.support.DefaultListableBeanFactory$DependencyObjectProvider.getIfAvailable(DefaultListableBeanFactory.java:2030) ~[spring-beans-5.3.19.jar:5.3.19]
  at org.springframework.beans.factory.support.DefaultListableBeanFactory$DependencyObjectProvider.ifAvailable(DefaultListableBeanFactory.java:2041) ~[spring-beans-5.3.19.jar:5.3.19]
  at com.azure.spring.cloud.autoconfigure.context.AzureTokenCredentialAutoConfiguration.azureCredentialBuilderFactory(AzureTokenCredentialAutoConfiguration.java:74) ~[spring-cloud-azure-autoconfigure-4.0.0.jar:4.0.0]
  at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
  at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
  ...

To Reproduce
Create Spring Boot Application with two ThreadPoolTaskExecutor and Azure Spring Cloud (e.g. Key Vault Secrets enabled).

Code Snippet

  @Bean
  public ThreadPoolTaskExecutor threadPoolTaskExecutor1() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setMaxPoolSize(10);
    executor.setCorePoolSize(10);
    executor.initialize();
    return executor;
  }

  @Bean
  public ThreadPoolTaskExecutor threadPoolTaskExecutor2() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setMaxPoolSize(10);
    executor.setCorePoolSize(10);
    executor.initialize();
    return executor;
  }

Expected behavior
If there are more than 1 ThreadPoolTaskExecutors, the auto configuration should skip setting one in the DefaultAzureCredentialBuilderFactory. Simple solution would be to replace threadPoolTaskExecutors.ifAvailable by threadPoolTaskExecutors.ifUnique.

Setup (please complete the following information):

  • OS: any
  • IDE: any
  • Library/Libraries: Spring Boot 2.6.7, com.azure.spring:spring-cloud-azure-autoconfigure:4.0.0
  • Java version: 11
  • App Server/Environment: Simple Spring Boot App
  • Frameworks: Spring Boot

Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Bug Description Added
  • Repro Steps Added
  • Setup information Added
@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Apr 26, 2022
@joshfree joshfree added Client This issue points to a problem in the data-plane of the library. azure-spring All azure-spring related issues labels Apr 26, 2022
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Apr 26, 2022
@joshfree
Copy link
Member

Hi @nioertel thank you for reaching out to us via this GitHub issue. Someone from the Azure Spring team will follow up shortly.

/cc @saragluna

@saragluna saragluna moved this to Todo in Spring Cloud Azure Apr 27, 2022
@saragluna saragluna added bug This issue requires a change to an existing behavior in the product in order to be resolved. and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Apr 27, 2022
@ghost ghost added the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Apr 27, 2022
@saragluna saragluna added this to the [2022] May milestone Apr 27, 2022
@saragluna saragluna moved this from Todo to In Progress in Spring Cloud Azure Apr 27, 2022
Repository owner moved this from In Progress to Done in Spring Cloud Azure Apr 28, 2022
@saragluna
Copy link
Member

The change will go out in 4.1.0 later this month.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
azure-spring All azure-spring related issues bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team
Projects
Archived in project
3 participants