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

java.util.ConcurrentModificationException when using 2 schedulers and 2 rest clients #22281

Closed
nikifmak opened this issue Dec 16, 2021 · 4 comments · Fixed by #22286
Closed
Labels
area/rest-client kind/bug Something isn't working
Milestone

Comments

@nikifmak
Copy link

nikifmak commented Dec 16, 2021

Describe the bug

1. Dependencies

I am using Quarkus version 2.5.3.Final

pom.xml

<dependencies>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy-reactive-jackson</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-rest-client-reactive</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy-reactive</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-scheduler</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-rest-client-reactive-jackson</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-arc</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-junit5</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.rest-assured</groupId>
      <artifactId>rest-assured</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

2. Files

1.

@ApplicationScoped
public class FirstScheduler {

    public static final Logger logger = LoggerFactory.getLogger(FirstScheduler.class);

    @Inject
    @RestClient
    FirstClient firstClient;

    @Scheduled(every = "5m")
    void reload() {
        logger.info("FirstScheduler");
    }
}

2.

@ApplicationScoped
public class SecondScheduler {

    public static final Logger logger = LoggerFactory.getLogger(SecondScheduler.class);

    @Inject
    @RestClient
    SecondClient secondClient;

    @Scheduled(every = "5m")
    void reload() {
        logger.info("SecondScheduler");
    }
}

3.

@Path("/first")
@RegisterRestClient(configKey = "FirstClient")
public interface FirstClient {

    @GET
    @Path("/")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    Uni<Object> fetch();
}

4.

@Path("/second")
@RegisterRestClient(configKey = "SecondClient")
public interface SecondClient {

    @POST
    @Path("/")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    Uni<List<Object>> fetch();
}

Expected behavior

The application should boot without errors.

Actual behavior

The application boots but an error is thrown.

2021-12-16 14:31:04,019 ERROR [io.qua.sch.run.SimpleScheduler] (executor-thread-0) Error occured while executing task for trigger IntervalTrigger [id=1_com.test.schedulers.SecondScheduler_ScheduledInvoker_reload_e52552f7a8d66bad0704dbc1bc5053b5a80c5548, interval=300000]: java.lang.RuntimeException: Error injecting com.test.clients.SecondClient com.test.schedulers.SecondScheduler.secondClient
        at com.test.schedulers.SecondScheduler_Bean.create(Unknown Source)
        at com.test.schedulers.SecondScheduler_Bean.create(Unknown Source)
        at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:96)
        at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:29)
        at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:26)
        at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:26)
        at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
        at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:26)
        at io.quarkus.arc.impl.ClientProxies.getApplicationScopedDelegate(ClientProxies.java:18)
        at com.test.schedulers.SecondScheduler_ClientProxy.arc$delegate(Unknown Source)
        at com.test.schedulers.SecondScheduler_ClientProxy.reload(Unknown Source)
        at com.test.schedulers.SecondScheduler_ScheduledInvoker_reload_e52552f7a8d66bad0704dbc1bc5053b5a80c5548.invokeBean(Unknown Source)
        at io.quarkus.arc.runtime.BeanInvoker.invoke(BeanInvoker.java:20)
        at io.quarkus.scheduler.runtime.SimpleScheduler$ScheduledTask$1.run(SimpleScheduler.java:274)
        at io.quarkus.vertx.core.runtime.VertxCoreRecorder$13.runWith(VertxCoreRecorder.java:548)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
        at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
        at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.util.ConcurrentModificationException
        at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1225)
        at io.quarkus.restclient.config.RestClientsConfig.getClientConfig(RestClientsConfig.java:65)
        at io.quarkus.rest.client.reactive.runtime.RestClientCDIDelegateBuilder.clientConfigByClassName(RestClientCDIDelegateBuilder.java:340)
        at io.quarkus.rest.client.reactive.runtime.RestClientCDIDelegateBuilder.configureBaseUrl(RestClientCDIDelegateBuilder.java:299)
        at io.quarkus.rest.client.reactive.runtime.RestClientCDIDelegateBuilder.build(RestClientCDIDelegateBuilder.java:63)
        at io.quarkus.rest.client.reactive.runtime.RestClientCDIDelegateBuilder.build(RestClientCDIDelegateBuilder.java:59)
        at io.quarkus.rest.client.reactive.runtime.RestClientCDIDelegateBuilder.createDelegate(RestClientCDIDelegateBuilder.java:42)
        at io.quarkus.rest.client.reactive.runtime.RestClientReactiveCDIWrapperBase.<init>(RestClientReactiveCDIWrapperBase.java:16)
        at com.test.clients.SecondClient$$CDIWrapper.<init>(Unknown Source)
        at com.test.clients.SecondClient$$CDIWrapper_Subclass.<init>(Unknown Source)
        at com.test.clients.SecondClient$$CDIWrapper_Bean.create(Unknown Source)
        at com.test.clients.SecondClient$$CDIWrapper_Bean.create(Unknown Source)
        at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:96)
        at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:29)
        at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:26)
        at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:26)
        at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
        at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:26)
        at com.test.clients.SecondClient$$CDIWrapper_Bean.get(Unknown Source)
        at com.test.clients.SecondClient$$CDIWrapper_Bean.get(Unknown Source)
        ... 21 more


How to Reproduce?

Download the zip
scheduler-clients-test.zip
and run it

Output of uname -a or ver

Darwin macbookpacegrey 21.1.0 Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:23 PDT 2021; root:xnu-8019.41.5~1/RELEASE_X86_64 x86_64

Output of java -version

openjdk version "11.0.9.1" 2020-11-04

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.5.3.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.1

Additional information

The same behaviour exists from 2.5.1.Final version

@nikifmak nikifmak added the kind/bug Something isn't working label Dec 16, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Dec 16, 2021

/cc @michalszynkiewicz, @mkouba

@gsmet
Copy link
Member

gsmet commented Dec 16, 2021

Can you attach a small zip with a reproducer? It helps us a lot. Thanks!

@nikifmak
Copy link
Author

nikifmak commented Dec 16, 2021

Yeah sorry for not attaching it. Thanks for help :)
scheduler-clients-test.zip

@geoand
Copy link
Contributor

geoand commented Dec 16, 2021

#22286 fixes the issue.

geoand added a commit to geoand/quarkus that referenced this issue Dec 16, 2021
michalszynkiewicz added a commit that referenced this issue Dec 17, 2021
Fix concurrency issue with REST Client Config
@quarkus-bot quarkus-bot bot added this to the 2.7 - main milestone Dec 17, 2021
@gsmet gsmet modified the milestones: 2.7 - main, 2.5.4.Final Dec 17, 2021
gsmet pushed a commit to gsmet/quarkus that referenced this issue Dec 17, 2021
gsmet pushed a commit to gsmet/quarkus that referenced this issue Dec 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rest-client kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants