OpenFeign / OpenFeign/feign

Deadlock when using feign in @PostConstruct with CompletableFuture

Open
#2,544 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feedback provided question
Dominant language
Java
Stars
9.8k
Forks
1.9k
Avg merge
1d 2h
Merged PRs (30d)
41

Description

"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(java.base@17.0.12/CompletableFuture.java:1768)
        at java.util.concurrent.CompletableFuture$AsyncSupply.exec(java.base@17.0.12/CompletableFuture.java:1760)
        at java.util.concurrent.ForkJoinTask.doExec(java.base@17.0.12/ForkJoinTask.java:373)
        at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(java.base@17.0.12/ForkJoinPool.java:1182)
        at java.util.concurrent.ForkJoinPool.scan(java.base@17.0.12/ForkJoinPool.java:1655)
        at java.util.concurrent.ForkJoinPool.runWorker(java.base@17.0.12/ForkJoinPool.java:1622)
        at java.util.concurrent.ForkJoinWorkerThread.run(java.base@17.0.12/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(java.base@17.0.12/CompletableFuture.java:1768)
        at java.util.concurrent.CompletableFuture$AsyncSupply.exec(java.base@17.0.12/CompletableFuture.java:1760)
        at java.util.concurrent.ForkJoinTask.doExec(java.base@17.0.12/ForkJoinTask.java:373)
        at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(java.base@17.0.12/ForkJoinPool.java:1182)
        at java.util.concurrent.ForkJoinPool.scan(java.base@17.0.12/ForkJoinPool.java:1655)
        at java.util.concurrent.ForkJoinPool.runWorker(java.base@17.0.12/ForkJoinPool.java:1622)
        at java.util.concurrent.ForkJoinWorkerThread.run(java.base@17.0.12/ForkJoinWorkerThread.java:165)

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported @PostConstruct path and the CompletableFuture execution shown in the thread dump. Trace the calls through SpringDecoder, ResponseEntityDecoder, and SynchronousMethodHandler, then reproduce the Feign call from CompletableFuture during bean initialization. Done means identifying the deadlock cause and documenting or verifying a safe resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.