google-code-export / wro4j

Automatically exported from code.google.com/p/wro4j
1 stars 1 forks source link

File descriptor leak #864

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Using a simple application with WRO, attach the java agent at 
http://file-leak-detector.kohsuke.org/ when the application starts. Then, hit 
WRO a few times, and notice that the file descriptor count rises. If you then a 
few minutes, the count falls back to where it started (I assume this is because 
Java runs the finalizers on the un-closed streams).

This is the stack trace of file descriptors:
#37 C:\<something>\something.js by 
thread:wro4j-ro.isdc.wro.model.resource.support.change.ResourceWatcher-2-thread-
7 on Mon Mar 31 16:24:45 EDT 2014
    at java.io.FileInputStream.<init>(FileInputStream.java:139)
    at java.io.FileInputStream.<init>(FileInputStream.java:97)
    at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90)
    at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188)
    at ro.isdc.wro.model.resource.locator.UrlUriLocator.locate(UrlUriLocator.java:85)
    at ro.isdc.wro.model.resource.locator.factory.InjectableUriLocatorFactoryDecorator.locate(InjectableUriLocatorFactoryDecorator.java:37)
    at ro.isdc.wro.model.resource.support.change.ResourceChangeDetector.checkChangeForGroup(ResourceChangeDetector.java:71)
    at ro.isdc.wro.model.resource.support.change.ResourceWatcher.isChanged(ResourceWatcher.java:279)
    at ro.isdc.wro.model.resource.support.change.ResourceWatcher.checkResourceChange(ResourceWatcher.java:259)
    at ro.isdc.wro.model.resource.support.change.ResourceWatcher.access$100(ResourceWatcher.java:60)
    at ro.isdc.wro.model.resource.support.change.ResourceWatcher$2.call(ResourceWatcher.java:231)
    at ro.isdc.wro.model.resource.support.change.ResourceWatcher$2.call(ResourceWatcher.java:228)
    at ro.isdc.wro.config.support.ContextPropagatingCallable$1.call(ContextPropagatingCallable.java:34)
    at ro.isdc.wro.config.support.ContextPropagatingCallable.call(ContextPropagatingCallable.java:62)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)

I believe the problem is at 
https://github.com/alexo/wro4j/blob/v1.7.4/wro4j-core/src/main/java/ro/isdc/wro/
model/resource/support/change/ResourceChangeDetector.java#L71 - 
locatorFactory.locate(uri) returns an InputStream, but neither this method nor 
hashStrategy.getHash close the InputStream.

Original issue reported on code.google.com by candrews...@gmail.com on 31 Mar 2014 at 8:28

GoogleCodeExporter commented 9 years ago
Nice catch!

Original comment by alex.obj...@gmail.com on 31 Mar 2014 at 8:31

GoogleCodeExporter commented 9 years ago
Pull request: https://github.com/alexo/wro4j/pull/176

I'm hoping you can review for more such leaks too :)

Thanks!

Original comment by candrews...@gmail.com on 31 Mar 2014 at 8:56

GoogleCodeExporter commented 9 years ago
Merged in 1.7.x

Original comment by alex.obj...@gmail.com on 2 Apr 2014 at 4:19