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

Deadlock when using feign in @PostConstruct with CompletableFuture #2544

Open
jinkshower opened this issue Sep 11, 2024 · 1 comment
Open
Labels
feedback provided Feedback has been provided to the author question General usage or 'how-to' questions

Comments

@jinkshower
Copy link

"ForkJoinPool.commonPool-worker-1" #39 daemon prio=5 os_prio=31 cpu=2.77ms elapsed=14.76s tid=0x000000015e4a4600 nid=0x8c0b waiting for monitor entry  [0x0000000170441000]
   java.lang.Thread.State: BLOCKED (on object monitor)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:217)
        - waiting to lock <0x0000000700dfab40> (a java.util.concurrent.ConcurrentHashMap)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:275)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
        at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:254)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1443)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory$DependencyObjectProvider.getObject(DefaultListableBeanFactory.java:2070)
        at org.springframework.cloud.openfeign.support.SpringDecoder.decode(SpringDecoder.java:66)
        at org.springframework.cloud.openfeign.support.ResponseEntityDecoder.decode(ResponseEntityDecoder.java:62)
        at feign.optionals.OptionalDecoder.decode(OptionalDecoder.java:36)
        at feign.InvocationContext.decode(InvocationContext.java:114)
        at feign.InvocationContext.proceed(InvocationContext.java:88)
        at feign.ResponseInterceptor$Chain$$Lambda$1184/0x000000b001941a48.next(Unknown Source)
        at feign.ResponseHandler.handleResponse(ResponseHandler.java:63)
        at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:114)
        at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:70)
        at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:99)
        at jdk.proxy2.$Proxy159.fetch(jdk.proxy2/Unknown Source)
        at hiyen.galmanhae.dataprocess.application.CongestionService.fetch(CongestionService.java:22)
        at hiyen.galmanhae.dataprocess.DataProcessor.aggregatePlace(DataProcessor.java:61)
        at hiyen.galmanhae.dataprocess.DataProcessor.lambda$toFuture$0(DataProcessor.java:50)
        at hiyen.galmanhae.dataprocess.DataProcessor$$Lambda$1520/0x000000b001b86a68.get(Unknown Source)
        at java.util.concurrent.CompletableFuture$AsyncSupply.run([email protected]/CompletableFuture.java:1768)
        at java.util.concurrent.CompletableFuture$AsyncSupply.exec([email protected]/CompletableFuture.java:1760)
        at java.util.concurrent.ForkJoinTask.doExec([email protected]/ForkJoinTask.java:373)
        at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec([email protected]/ForkJoinPool.java:1182)
        at java.util.concurrent.ForkJoinPool.scan([email protected]/ForkJoinPool.java:1655)
        at java.util.concurrent.ForkJoinPool.runWorker([email protected]/ForkJoinPool.java:1622)
        at java.util.concurrent.ForkJoinWorkerThread.run([email protected]/ForkJoinWorkerThread.java:165)

"ForkJoinPool.commonPool-worker-2" #40 daemon prio=5 os_prio=31 cpu=3.25ms elapsed=14.76s tid=0x000000015e4a4c00 nid=0x9e1b waiting for monitor entry  [0x000000017064d000]
   java.lang.Thread.State: BLOCKED (on object monitor)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:217)
        - waiting to lock <0x0000000700dfab40> (a java.util.concurrent.ConcurrentHashMap)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:275)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
        at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:254)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1443)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory$DependencyObjectProvider.getObject(DefaultListableBeanFactory.java:2070)
        at org.springframework.cloud.openfeign.support.SpringDecoder.decode(SpringDecoder.java:66)
        at org.springframework.cloud.openfeign.support.ResponseEntityDecoder.decode(ResponseEntityDecoder.java:62)
        at feign.optionals.OptionalDecoder.decode(OptionalDecoder.java:36)
        at feign.InvocationContext.decode(InvocationContext.java:114)
        at feign.InvocationContext.proceed(InvocationContext.java:88)
        at feign.ResponseInterceptor$Chain$$Lambda$1184/0x000000b001941a48.next(Unknown Source)
        at feign.ResponseHandler.handleResponse(ResponseHandler.java:63)
        at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:114)
        at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:70)
        at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:99)
        at jdk.proxy2.$Proxy159.fetch(jdk.proxy2/Unknown Source)
        at hiyen.galmanhae.dataprocess.application.CongestionService.fetch(CongestionService.java:22)
        at hiyen.galmanhae.dataprocess.DataProcessor.aggregatePlace(DataProcessor.java:61)
        at hiyen.galmanhae.dataprocess.DataProcessor.lambda$toFuture$0(DataProcessor.java:50)
        at hiyen.galmanhae.dataprocess.DataProcessor$$Lambda$1520/0x000000b001b86a68.get(Unknown Source)
        at java.util.concurrent.CompletableFuture$AsyncSupply.run([email protected]/CompletableFuture.java:1768)
        at java.util.concurrent.CompletableFuture$AsyncSupply.exec([email protected]/CompletableFuture.java:1760)
        at java.util.concurrent.ForkJoinTask.doExec([email protected]/ForkJoinTask.java:373)
        at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec([email protected]/ForkJoinPool.java:1182)
        at java.util.concurrent.ForkJoinPool.scan([email protected]/ForkJoinPool.java:1655)
        at java.util.concurrent.ForkJoinPool.runWorker([email protected]/ForkJoinPool.java:1622)
        at java.util.concurrent.ForkJoinWorkerThread.run([email protected]/ForkJoinWorkerThread.java:165)

I have no problem when using feignclient in @PostConstruct but when I use it with CompletableFuture, I get above deadlock

@kdavisk6
Copy link
Member

I'm not sure this is a Feign issue directly, but I'm going to make a guess that you are trying to initialize a FeignClient in a thread. Feign Client initialization is not thread safe, but an initialized Feign Client should be thread safe.

Looking at the stack trace, there appears to be dependency injection occurring as part of the decode operation. It's in that operation where the deadlock occurs. If you can provide a minimal reproducible example, we may be able to help track it down.

@kdavisk6 kdavisk6 added question General usage or 'how-to' questions feedback provided Feedback has been provided to the author labels Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feedback provided Feedback has been provided to the author question General usage or 'how-to' questions
Projects
None yet
Development

No branches or pull requests

2 participants