-
-
Notifications
You must be signed in to change notification settings - Fork 5
Fix class loading error when a thread is interrupted #8
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
Conversation
|
Reverting to the performance degradation of union file system is not a valid solution. The eventual goal is to strip out union file system into its own project and only have it avaliable at dev time. What actually closes the file system? If this is an issue with the ZipFileSystem then it would lead me to think this is a java bug and should be reported to them. If this is not an issue in the build in classloader. Then im curious how it deals with this case. Maybe a better solution is to open the file system in a way that blocks other threads from closing it. Or handling this edge case and reopening the filesystem. Is there a way to reliably write a unit test for this? |
|
For context, I discovered the issue when using the mongodb-driver-sync library to connect to a database. When I close the connection, the library interrupts the threads in its thread pool and then the classloader explodes. The zip filesystem is backed internally by a It is possible to disable this behavior by calling So an alternative solution is to do the same trick on a standard zip filesystem. |
|
That would indeed be the preferred option then. Also, what i mean by java bug is the overall behavior of classes not being able to be loaded from a zip if one thread gets interrupted. How does normal java deal with that? Is it an issue that arrives with the standard classloader. If not. Why not. |
|
Should
I just took a look at standard classloaders, |
Is there any way to get our own ZipFileSystem without the duplicate file system issue? A URLConnection should have the same issues as i think it's based by ZFS (hence using a url to force the FS cache) Another potentially stupid solution would be to see what it takes to support ZipFile in addition to the NIO system. So that we can skip NIO for the common usecase. I am.unsure of the feasibility or best route to go. But the options are worth looking into if/when someone has time. |
|
I investigated a bit more, I was wrong. URLConnection is only the fallback when protocol is unknown. When protocol is Anyway, I updated the PR to have a unit test and the discussed solution. |
Ah, interesting
I shall take a look when I get a chance. Thanks. No "new" hacks. Just moving some of the existing. And doesn't use UFS. |
|
Okay so I'm back in town and alive enough to look into this. But that would be a big refactor/breaking change that I need to think about more. This PR looks fine, Not happy that it does a hack, but its a hack that the UFS has been doing for years so guess it works. I'm gunna add a comment linking to this PR in the util class for Future Me to remember when designing a breaking change. |
When a thread is interrupted while loading a class from disk, the underlying zip filesystem is closed. Any further class loads from the same module will fail.
How to reproduce:
This will result in a
ClassNotFoundException.By adding
printStackTrace()inSecureModuleClassLoader#findClass(module, name)I can get the following stacktrace:This error already existed in the past and was fixed by commit 4e05cab. However it has been fixed only for the union filesystem. Since zip filesystem is currently preferred when possible, this issue still occurs.
In this PR, I solve this issue by always preferring the union filesystem, even when there is a single path.