melix / jmh-gradle-plugin

Integrates the JMH benchmarking framework with Gradle
Apache License 2.0
662 stars 88 forks source link

Fix file descriptor leak through worker classpath #173

Closed oehme closed 3 years ago

oehme commented 3 years ago

Workers created through the worker API live as long as the Gradle daemon. Therefor, they should not have any JARs on their classpath that are part of the project being built. Otherwise, the worker keeps these JARs open, leading to a file descriptor leak and an unability to clean the project on Windows. Also, on every change to the dependencies, a new worker would be created, greatly increasing memory pressure on the system. Finally, the workers of different subprojects would be incompatible due to their different classpaths, increasing the number of spwawned workers even more.

This fix changes the worker such that only JMH is put on the worker classpath. The project's own dependencies are passed to the worker as arguments. Some trickery was necessary, because JMH insists on looking for project-specific files on its own classpath. This should probably be reported as a bug to JMH. It should either look on the Thread's context classloader (which we could change) or make these locations externally configurable on the Runner class.

Fixes #170, #163