You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Knut Anders Hatlen (JIRA)" <ji...@apache.org> on 2014/03/25 10:19:43 UTC

[jira] [Commented] (DERBY-2162) Shutting down a database loaded from a jar file via the classpath and URLClassLoader leaves an open file reference to the jar file containing the database.

    [ https://issues.apache.org/jira/browse/DERBY-2162?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13946323#comment-13946323 ] 

Knut Anders Hatlen commented on DERBY-2162:
-------------------------------------------

Another way to get the test case to pass, also on Java versions earlier than 7, is to call the URLConnection.setDefaultUseCaches() method first to disable caching of the jar files opened by URLClassLoader. That seems to make gc capable of freeing the file handle after the context class loader has been set to null at the end of the test case. An explicit call to System.gc() is needed before trying to delete the jar file, though, in order to make sure gc has run and released the file handle.

This latter approach is probably too brittle to use in the regression tests, since System.gc() doesn't guarantee that all garbage is cleaned up. But I think these results support Dan's initial analysis that the file handle is kept open by the Java platform itself and not by Derby. I also think it means the solution for this problem must be implemented in the application layer (applications could either close the URLClassLoader when they are done with it, or disable caching of jar files). Having Derby close the URLClassLoader on shutdown is not an option, I think, as it is not possible for Derby to determine whether or not the application will still need the class loader after the Derby engine has been shut down.

> Shutting down a database loaded from a jar file via the classpath and URLClassLoader  leaves an open file reference to the jar file containing the database.
> ------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-2162
>                 URL: https://issues.apache.org/jira/browse/DERBY-2162
>             Project: Derby
>          Issue Type: Bug
>          Components: Services
>    Affects Versions: 10.2.1.6, 10.3.1.4
>            Reporter: Daniel John Debrunner
>            Assignee: Knut Anders Hatlen
>            Priority: Minor
>              Labels: derby_triage10_5_2
>
> A bug in java.net.URLClassLoader causes the underlying jar file to be held open once a resource has been fetched and opened.
> Loading a class or just accessing the URL for the resource does not keep the jar open. Reported the bug to Sun, it is similar to the existing bug Java bug 4950148 but in this case no amount of garbage collection will close the jar.
> Derby exposes this as all containers/files are opened using as resources when loading the database from the classpath.
> On windows this is seen as the inability to delete the jar file, seen by the fixture testDatabaseInClasspath in DatabaseClassLoadingTest.
> Similar to DERBY-2083 but due to a different cause.



--
This message was sent by Atlassian JIRA
(v6.2#6252)