Skip to content

Fix static ExecutorService ClassLoader leak in AsyncFeign#3277

Open
velo wants to merge 1 commit intomasterfrom
fix/3178-static-executor-classloader-leak
Open

Fix static ExecutorService ClassLoader leak in AsyncFeign#3277
velo wants to merge 1 commit intomasterfrom
fix/3178-static-executor-classloader-leak

Conversation

@velo
Copy link
Member

@velo velo commented Mar 18, 2026

Summary

Fixes #3178

  • Replaced the static LazyInitializedExecutorService singleton in AsyncFeign and CoroutineFeign with a per-instance factory method newDefaultExecutorService()
  • Each AsyncBuilder/CoroutineBuilder now creates its own ExecutorService instead of sharing a JVM-wide static one
  • This prevents ClassLoader leaks during servlet container redeployments (e.g., Tomcat), which previously caused Metaspace OOM

The root cause was that the static ExecutorService held strong references to the ContextClassLoader of the first application that loaded the class. On redeployment, the old ClassLoader could never be garbage collected because the static executor's threads still referenced it.

With this change, each builder gets its own cached thread pool. Since newCachedThreadPool reclaims idle threads after 60 seconds, threads from discarded feign clients will naturally clean up. Users who want explicit control can continue to provide their own ExecutorService via the client() builder method.

Test plan

  • All 601 core module tests pass
  • Kotlin module compiles successfully
  • AsyncFeignTest (52 tests) passes with no regressions

🤖 Generated with Claude Code

@QiuYucheng2003 — you reported this issue, could you review this fix?

…o fix ClassLoader leak (#3178)

Signed-off-by: Marvin Froeder <velo.br@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Static ExecutorService in AsyncFeign causes ClassLoader Leak (Metaspace OOM)

1 participant