Feign client lazy initialization fails when using CompletableFuture.supplyAsync() to call the Feign client initially

See original GitHub issue

Describe the bug Feign client initialization is always lazy. As such, the first calling thread triggers the initialization, which may be another Spring component (e.g. REST controller) using CompletableFuture.supplyAsync() to do so. This uses ForkJoinWorkerThread underneath, resulting in a ClassNotFoundException, if and only if running in a dockerized environment based on Spring Boot Build Image plugin.

Using other JVM Executors(except newWorkStealingExecutor), e.g. fixedSizeThreadExecutor(), does not result in this behavior. Also eagerly initializing the Feign client by calling it synchronously, e.g. from within a CommandLineRunner, circumvents this. Once, the Feign client is properly initialized, there is no problem, however, Feign does not yet support eager initialization.

Sample A sample project with instructions to reproduce is provided here: https://github.com/maverick1601/openfeign-build-image-error

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:18

github_iconTop GitHub Comments

3reactions
OlgaMaciaszekcommented, Jan 29, 2021

@maverick1601, thanks for reporting this. Will discuss it with the team and get back to you.

2reactions
HJK181commented, Oct 5, 2022

I’m facing the exact same problem after an update from Spring 2.3 to Spring 2.7 + Java update from 14 to 17. We are not using any @Async or CompletableFuture, but the feign client is called by a Grizzly Thread (started as part of a Spring Boot app) that is part of our core infrastructure and needs to call another running Spring Boot app via Feign. This used to work without any problems before the update. Disappointed way too often to see such an issue open for such a long time with no prospect of a solution

Read more comments on GitHub >

github_iconTop Results From Across the Web

spring - Feign Client : use jar running (CompletableFuture ...
supplyAsync call Feign Client throw java.lang. ... thenApply(e -> futures.stream().map(CompletableFuture::join) .collect(Collectors.
Read more >
Spring Cloud
Spring WebFlux WebClient as a Load Balancer Client; 3.7. ... Refresh scope beans are lazy proxies that initialize when they are used (that...
Read more >
Spring Cloud Sleuth
The initial span that starts a trace is called a root span . The value of span id of that span is equal...
Read more >
Spring Cloud
4.1. Quick Start. This quick start walks through using both the server and the client of Spring Cloud Config Server. First, start the...
Read more >
Spring Cloud
Refresh scope beans are lazy proxies that initialize when they are used (i.e. when a ... Spring Cloud has support for Feign (a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found