netty: Classloader memory leak via JNI global references
Expected behavior
Netty (in this case via reactor-netty) can be used in conjunction with multiple classloaders, allowing classloaders to be properly unloaded if not referenced anymore. (in this case this is important for a gradle plugin)
Actual behavior
When using netty-resolver-dns-native-macos, a classloader and all its classes can not be unloaded even if not referenced anymore as the class io.netty.resolver.dns.macos.DnsResolver is a GC root as a JNI global reference.
This class (and other required classes) are loaded via NETTY_JNI_UTIL_LOAD_CLASS (https://github.com/netty/netty/blob/79d3fa52dc0ee07ccc1d9c68648b57dc3bafc88e/resolver-dns-native-macos/src/main/c/netty_resolver_dns_macos.c#L186) which uses NewGlobalRef (https://github.com/netty/netty-jni-util/blob/8d820fba781882f8a7fe94efb7656d1413ff8bb8/src/main/c/netty_jni_util.h#L45).
Maybe using weak global references instead of global references of the classes is a solution.
Or is there any other solutions how to safely use netty with dynamic classloaders?
Netty version
4.1.94.Final via reactor-netty:1.1.8
JVM version (e.g. java -version)
Any
OS version (e.g. uname -a)
MacOS
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 30 (30 by maintainers)
Commits related to this issue
- Fix Classloader memory leak via JNI global references Motivation: We did forget to call NETTY_JNI_UTIL_UNLOAD_CLASS for one class which caused a JNI global reference to not be deleted. Modification... — committed to netty/netty by normanmaurer a year ago
- Fix Classloader memory leak via JNI global references (#13481) Motivation: We did forget to call NETTY_JNI_UTIL_UNLOAD_CLASS for one class which caused a JNI global reference to not be deleted. ... — committed to netty/netty by normanmaurer a year ago
- Fix Classloader memory leak via JNI global references Motivation: We did forget to call NETTY_JNI_UTIL_UNLOAD_CLASS for one class which caused a JNI global reference to not be deleted. Modification... — committed to netty/netty by normanmaurer a year ago
- Add macros to load classes and store as weak reference Motivation: When classes are loaded and stored via a global reference we might end up with issues when we try to unload the classloader due of ... — committed to netty/netty-jni-util by normanmaurer a year ago
- Add macros to load classes and store as weak reference (#14) Motivation: When classes are loaded and stored via a global reference we might end up with issues when we try to unload the classloade... — committed to netty/netty-jni-util by normanmaurer a year ago
- Prevent classloader leak via JNI Motivation: We should use weak references to hold global references to our own classes as otherwise it will be not possible to unload the classloader. Modifications... — committed to netty/netty by normanmaurer 10 months ago
- Prevent JNI classloader leak Motivation: We should use weak references to hold global references to our own classes as otherwise it will be not possible to unload the classloader. Modifications: U... — committed to netty/netty-incubator-codec-quic by normanmaurer 10 months ago
- Prevent classloader leak via JNI Motivation: We should use weak references to hold global references to our own classes as otherwise it will be not possible to unload the classloader. Modifications... — committed to netty/netty-tcnative by normanmaurer 10 months ago
- Prevent classloader leak via JNI (#13584) Motivation: We should use weak references to hold global references to our own classes as otherwise it will be not possible to unload the classloader. ... — committed to netty/netty by normanmaurer 10 months ago
- Prevent JNI classloader leak (#574) Motivation: We should use weak references to hold global references to our own classes as otherwise it will be not possible to unload the classloader. Modif... — committed to netty/netty-incubator-codec-quic by normanmaurer 10 months ago
- Prevent classloader leak via JNI (#817) Motivation: We should use weak references to hold global references to our own classes as otherwise it will be not possible to unload the classloader. M... — committed to netty/netty-tcnative by normanmaurer 10 months ago
- Prevent classloader leak via JNI Motivation: We should use weak references to hold global references to our own classes as otherwise it will be not possible to unload the classloader. Modifications... — committed to netty/netty by normanmaurer 10 months ago
- Prevent classloader leak via JNI Motivation: We should use weak references to hold global references to our own classes as otherwise it will be not possible to unload the classloader. Modifications... — committed to netty/netty by normanmaurer 10 months ago
- Prevent classloader leak via JNI (#13586) Motivation: We should use weak references to hold global references to our own classes as otherwise it will be not possible to unload the classloader. ... — committed to netty/netty by normanmaurer 10 months ago
- Do not try to delete a global handle with the local handles APIs (#588) Motivation: The code introduced as part of https://github.com/netty/netty/issues/13480 contained a bug which could crash the J... — committed to netty/netty by normanmaurer 9 months ago
- Do not try to delete a global handle with the local handles APIs (#588) Motivation: The code introduced as part of https://github.com/netty/netty/issues/13480 contained a bug which could crash the J... — committed to netty/netty by normanmaurer 9 months ago
- Do not try to delete a global handle with the local handles APIs (#13640) Motivation: The code introduced as part of https://github.com/netty/netty/issues/13480 contained a bug which could crash... — committed to netty/netty by normanmaurer 9 months ago
- Do not try to delete a global handle with the local handles APIs (#13640) Motivation: The code introduced as part of https://github.com/netty/netty/issues/13480 contained a bug which could crash... — committed to netty/netty by normanmaurer 9 months ago
@SgtSilvio PTAL https://github.com/netty/netty/pull/13584
@SgtSilvio yes taking a heap dump is fineā¦I am also not sure if there is any other way to solve it but I would like to explore this first before making any changes.
Let me do some experiments