Skip to content

ClassLoader Leak using TestProfiles (OutOfMemoryError: Metaspace) #38774

Open
@xuckz

Description

Describe the bug

Using multiple TestProfiles results in OutOfMemoryError: Metaspace
It seems that running a @QuarkusTest with its own @\TestProfile is not cleaned up properly after the Test has finished, and all QuarkusClassLoaders used are permanently stored in MetaSpace.

Each Test adding its own ClassLoader to MetaSpace until the OutOfMemoryError occurs.

Increasing the MetaSpace for each @QuarkusTest with its own @\TestProfile is a limited workaround.

Edit: I think this might be related to #12498 since the Heap Space is also effected.

Edit2: Screenshot added

image-2024-02-13-13-01-49-831

Expected behavior

The expected behavior would be, that you are not limited to any amount of @\TestProfil and that each @\TestProfile would not increase the amount of MetaSpace required.

Actual behavior

Each @QuarkusTest with its own @\TestProfile requires the MetaSpace increased.

How to Reproduce?

Ready to go repo:
https://github.com/xuckz/quarkus-quickstarts-classloader-leak-demo
xuckz/quarkus-quickstarts-classloader-leak-demo@ccfa144

I used the quarkus-quickstarts/hibernate-orm-panache-quickstart as showcase:

  • Checkout https://github.com/quarkusio/quarkus-quickstarts
  • Open hibernate-orm-panache-quickstart/pom.xml
  • Limit MetaSpace (Since the amount of classes loaded by the quickstart examples is very low, we will have to cap the MetaSpace manually, otherwise we would need a lot of more tests)
<plugin>
    <!-- you need this specific version to integrate with the other build helpers -->
    <artifactId>maven-surefire-plugin</artifactId>
    <version>${surefire-plugin.version}</version>
    <configuration>
        <argLine>-XX:MetaspaceSize=128M -XX:MaxMetaspaceSize=256M</argLine>
        <systemPropertyVariables>
            <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
            <maven.home>${maven.home}</maven.home>
        </systemPropertyVariables>
    </configuration>
</plugin>
  • Add 1 empty Test class
package org.acme.hibernate.orm.panache.test;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;

@QuarkusTest
@TestProfile(LeakHunt1Test.LeakHuntTestProfile.class)
public class LeakHunt1Test {

    public static class LeakHuntTestProfile implements QuarkusTestProfile {
    }

    @Test
    void test() {
        System.out.println("asdfasdf");
    }
}
  • Run mvn test -> Everything runs fine
  • Copy LeakHunt1Test.java 9 more times
  • Run mvn test -> MetaSpace error

Output of uname -a or ver

Linux xxx 5.4.0-167-generic #184-Ubuntu SMP Tue Oct 31 09:21:49 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "17.0.9" 2023-10-17 OpenJDK Runtime Environment (build 17.0.9+9-Ubuntu-120.04) OpenJDK 64-Bit Server VM (build 17.0.9+9-Ubuntu-120.04, mixed mode, sharing)

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.6.3 Maven home: /usr/share/maven Java version: 17.0.9, vendor: Private Build, runtime: /usr/lib/jvm/java-17-openjdk-amd64 Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "5.4.0-167-generic", arch: "amd64", family: "unix"

Additional information

No response

Activity

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

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions