-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
0.10.0-SNAPSHOT is leaking heap memory via ThreadLocal #798
Comments
Here are some more details from my investigation:
I did the following dummy experiment (I know this would need further refinement, but I just wanted to see if this approach helps or not). Instead of running the build (method call
I created a new thread for each request and then just waited for that thread to finish:
I am well aware of the issues here (the catch is basically useless as any exception would be thrown inside that other thread). Also additional classloader configuration may be needed. In any case, this seems to "solve" the memory leak I am seeing. Once the thread finishes (stops), the |
@psiroky your analysis looks good to me, and the solution too. Could you raise a PR and handle the exception so that it's at least logged ? |
I was testing the latest bits from the
mvnd-0.10.x
branch (built locally) and noticed an increasing heap usage with every consequent build (of the same project). I am using the Quarkus project (tag 2.16.1.Final) and the simplest call I could think of -- justmvnd clean
.Here is the heap usage summary. It went from ~100MiB to ~1.8GiB in a matter of 20 seconds or so. The "steps" correspond to different
![mvnd-heap-usage](https://user-images.githubusercontent.com/670547/222926686-1108158d-341f-4802-85e6-361ae5e7f386.png)
mvnd clean
executions. My expectation would be that the heap usage goes back to the original number once the last execution finishes (actually it should probably go back to the original value after each execution - I noticed theSystem.gc()
call in the code -- so technically that can be ignored by JVM, but experimentally it should clean-up the heap after every execution).The heap dump summary looks like this:
![mvnd-leak-summary](https://user-images.githubusercontent.com/670547/222926820-e438256c-f0ba-4f08-a94a-75a06477f521.png)
Drilling down to the biggest portion of the occupied heap, we get this:
![mvnd-leak-example](https://user-images.githubusercontent.com/670547/222926870-707bc46f-be6a-47aa-aae5-e46884d0493f.png)
It seems like this is "caused" by the upgrade to Maven 3.9.0. I was not able to reproduce the same with mvnd 0.9.0, which bundles Maven 3.8.7.
My investigation so far:
ThreadLocal
and it is never cleared, accumulating data over subsequent buildsprivate MavenProject currentProject;
intoprivate ThreadLocal<MavenProject> currentProject = new ThreadLocal<>();
-- this looks somewhat suspicious, but I haven't yet confirmed if this is related or notMy environment:
mvnd-0.10.x
, specifically the commit c65f9feThe text was updated successfully, but these errors were encountered: