Skip to content

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

Closed

Description

@QiuYucheng2003

Description
The AsyncFeign class utilizes a private static inner class (LazyInitializedExecutorService) to hold a singleton ExecutorService. There is no mechanism provided to shut down this thread pool.

Root Cause

  1. Static Singleton: The executor is defined as private static final in LazyInitializedExecutorService (Lines 58-67).

  2. No Termination: The AsyncFeign class does not expose any shutdown() method or hook to clean up this resource.

  3. Container Context: While the threads are set as daemon, this only allows the JVM to exit. In a Servlet Container (like Tomcat), redeploying the application does not restart the JVM. The static thread pool retains strong references to the ContextClassLoader of the initial application, preventing it from being garbage collected.

Impact
·ClassLoader Leak: Each redeployment leaks the entire ClassLoader of the previous application version.

·Thread Leak: The number of active threads grows linearly with each redeployment.

·OOM: Eventually leads to Metaspace OutOfMemoryError.

Relevant Code
File: feign/AsyncFeign.java

private static class LazyInitializedExecutorService {
private static final ExecutorService instance =
Executors.newCachedThreadPool(
r -> {
final Thread result = new Thread(r);
result.setDaemon(true); // Daemon is insufficient for container redeployments
return result;
});
}

Suggested Fix
Avoid using a static singleton for the ExecutorService. Instead, manage the executor as an instance field within AsyncFeign, allowing it to be garbage collected when the client instance is discarded, or allow the user to provide their own ExecutorService via the builder.

Activity

  1. added
    bug
    on May 27, 2026
  2. velo commented on May 27, 2026

    @velo
    Member

    Thanks for the report. This project is community-maintained, and the maintainer won't implement fixes/features directly. If you want this to move forward, please open a pull request with automated tests that cover the change.\n\nFor bug reports, please also include (or confirm) a minimal reproduction, the affected version(s), and the full stack trace/logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions