[jetty-users] File handle leak when serving static files (Jetty 7.2)

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

[jetty-users] File handle leak when serving static files (Jetty 7.2)

Christoffer Bruun
Hi,

I have a Java program where Jetty is embedded.  Using lsof -p PID while running on linux I can see that I leak file handles to
all static files that are served using org.eclipse.jetty.servlet.DefaultServlet.

Inspecting the source I believe I have found the problem:

In org.eclipse.jetty.servlet.DefaultServlet.sendData(...)

There are a few occurrences of this construct:
   Buffer buffer = (content==null)?null:content.getIndirectBuffer();
 
The core of the implementation of HttpContent.ResourceAsHttpContent.getIndirectBuffer() is:
  ByteArrayBuffer buffer = new ByteArrayBuffer((int)_resource.length());
  buffer.readFrom(_resource.getInputStream(),(int)_resource.length()); 
  return buffer;

The InputStream returned by _resource.getInputStream() is not closed in getIndirectBuffer() and when the FileResource.getInputStream() is
nothing more than:
    return new FileInputStream(_file);

Then the InputStream is never closed and the file handle is leaked - or am I missing something ?

I have checked the sources of Jetty 7.6 and 8.1 and the implementations of HttpContent.ResourceAsHttpContent.getIndirectBuffer()
and FileResource.getInputStream() have not changed.



Best regards
Christoffer Bruun



_______________________________________________
jetty-users mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: [jetty-users] File handle leak when serving static files (Jetty 7.2)

Thomas Becker
Hi Christoffer,

thanks for reporting this. I opened a bug: "https://bugs.eclipse.org/bugs/show_bug.cgi?id=372190" where you can track the progress and will investigate on this.

Cheers,
Thomas

On 2/21/12 11:08 PM, Christoffer Bruun wrote:
Hi,

I have a Java program where Jetty is embedded.  Using lsof -p PID while running on linux I can see that I leak file handles to
all static files that are served using org.eclipse.jetty.servlet.DefaultServlet.

Inspecting the source I believe I have found the problem:

In org.eclipse.jetty.servlet.DefaultServlet.sendData(...)

There are a few occurrences of this construct:
   Buffer buffer = (content==null)?null:content.getIndirectBuffer();
 
The core of the implementation of HttpContent.ResourceAsHttpContent.getIndirectBuffer() is:
  ByteArrayBuffer buffer = new ByteArrayBuffer((int)_resource.length());
  buffer.readFrom(_resource.getInputStream(),(int)_resource.length()); 
  return buffer;

The InputStream returned by _resource.getInputStream() is not closed in getIndirectBuffer() and when the FileResource.getInputStream() is
nothing more than:
    return new FileInputStream(_file);

Then the InputStream is never closed and the file handle is leaked - or am I missing something ?

I have checked the sources of Jetty 7.6 and 8.1 and the implementations of HttpContent.ResourceAsHttpContent.getIndirectBuffer()
and FileResource.getInputStream() have not changed.



Best regards
Christoffer Bruun




_______________________________________________
jetty-users mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/jetty-users

-- 
thomas becker
[hidden email]

http://webtide.com / http://intalio.com
(the folks behind jetty and cometd)

_______________________________________________
jetty-users mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/jetty-users