Windows file handle leaks when using AntBuilder.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Windows file handle leaks when using AntBuilder.

Luke Daley-2

Hi,

I've found the source of the file handle leaks on the project I've been working on.

Ant internally uses an AntClassLoader. It keeps a cache of File → JarFile (AntClassLoader#jarFiles). This cache holds open JarFile objects. This cache is designed to be open for the duration of the build, and then closed at the end. The problem is that we never tell Ant that the build has finished and therefore it never closes this cache.

To remedy this, we need to make sure we call fireBuildFinished() on all ant Project instances when the build is over. For IsolatedAntBuilder this is easy. Does anyone have any good ideas on where to do this for Project.getAnt() ?

Reply | Threaded
Open this post in threaded view
|

Re: Windows file handle leaks when using AntBuilder.

Luke Daley-2

On 27 Nov 2013, at 16:50, Luke Daley wrote:

Hi,

I've found the source of the file handle leaks on the project I've been working on.

Ant internally uses an AntClassLoader. It keeps a cache of File → JarFile (AntClassLoader#jarFiles). This cache holds open JarFile objects. This cache is designed to be open for the duration of the build, and then closed at the end. The problem is that we never tell Ant that the build has finished and therefore it never closes this cache.

To remedy this, we need to make sure we call fireBuildFinished() on all ant Project instances when the build is over. For IsolatedAntBuilder this is easy. Does anyone have any good ideas on where to do this for Project.getAnt() ?

Forgot to mention, the reason this didn't show up in the profiler is that JarFile uses JNI and that actual file handle is at the native level (so YourKit couldn't see it).

Reply | Threaded
Open this post in threaded view
|

Re: Windows file handle leaks when using AntBuilder.

Luke Daley-2
Anyone have any opinions on this?

On 28 Nov 2013, at 2:54 am, Luke Daley <[hidden email]> wrote:

> On 27 Nov 2013, at 16:50, Luke Daley wrote:
>
> Hi,
>
> I've found the source of the file handle leaks on the project I've been working on.
>
> Ant internally uses an AntClassLoader. It keeps a cache of File → JarFile (AntClassLoader#jarFiles). This cache holds open JarFile objects. This cache is designed to be open for the duration of the build, and then closed at the end. The problem is that we never tell Ant that the build has finished and therefore it never closes this cache.
>
> To remedy this, we need to make sure we call fireBuildFinished() on all ant Project instances when the build is over. For IsolatedAntBuilder this is easy. Does anyone have any good ideas on where to do this for Project.getAnt() ?
>
> Forgot to mention, the reason this didn't show up in the profiler is that JarFile uses JNI and that actual file handle is at the native level (so YourKit couldn't see it).
>

--
Luke Daley
Principal Engineer, Gradleware
http://gradleware.com


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Windows file handle leaks when using AntBuilder.

Adam Murdoch

On 30 Jan 2014, at 6:27 am, Luke Daley <[hidden email]> wrote:

Anyone have any opinions on this?

Of course :)

One option is for DefaultAntBuilderFactory to implement a close method, and it can take care of cleaning up any AntBuilders it has produced.

To make this work, we’d also need to scope project scoped services when the project is finished with. We do this for build scoped services, but haven’t wired this up for project or task services yet. We’d need to do something similar to BuildScopeServiceRegistryFactory for project services, and task services too if you can be bothered at this stage, and then it should all just work.



On 28 Nov 2013, at 2:54 am, Luke Daley <[hidden email]> wrote:

On 27 Nov 2013, at 16:50, Luke Daley wrote:

Hi,

I've found the source of the file handle leaks on the project I've been working on.

Ant internally uses an AntClassLoader. It keeps a cache of File → JarFile (AntClassLoader#jarFiles). This cache holds open JarFile objects. This cache is designed to be open for the duration of the build, and then closed at the end. The problem is that we never tell Ant that the build has finished and therefore it never closes this cache.

To remedy this, we need to make sure we call fireBuildFinished() on all ant Project instances when the build is over. For IsolatedAntBuilder this is easy. Does anyone have any good ideas on where to do this for Project.getAnt() ?

Forgot to mention, the reason this didn't show up in the profiler is that JarFile uses JNI and that actual file handle is at the native level (so YourKit couldn't see it).


--
Luke Daley
Principal Engineer, Gradleware
http://gradleware.com


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email




--
Adam Murdoch
Gradle Co-founder
http://www.gradle.org
VP of Engineering, Gradleware Inc. - Gradle Training, Support, Consulting
http://www.gradleware.com