We're updating the issue view to help you get more done. 

compile leaks files

Description

clojure's compile function leaks file descriptors, i.e. it relies on garbage collection to close the files. I'm trying to use boot [1] on windows and ran into the problem, that files could not be deleted intermittently [2]. The problem is that clojure's compile function, or rather clojure.lang.RT.lastModified() relies on garbage collection to close files. lastModified() looks like:

1 2 3 4 5 6 7 8 static public long lastModified(URL url, String libfile) throws IOException{ if(url.getProtocol().equals("jar")) { return ((JarURLConnection) url.openConnection()).getJarFile().getEntry(libfile).getTime(); } else { return url.openConnection().getLastModified(); } }

Here's the stacktrace from file leak detector [3]:

1 2 3 4 5 6 7 8 9 10 #205 C:\Users\ralf\.boot\tmp\Users\ralf\home\steinmetz\2mg\-x24pa9\steinmetz\fx\config.clj by thread:clojure-agent-send-off-pool-0 on Sat Feb 14 19:58:46 UTC 2015 at java.io.FileInputStream.(FileInputStream.java:139) at java.io.FileInputStream.(FileInputStream.java:93) at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90) at sun.net.www.protocol.file.FileURLConnection.initializeHeaders(FileURLConnection.java:110) at sun.net.www.protocol.file.FileURLConnection.getLastModified(FileURLConnection.java:178) at clojure.lang.RT.lastModified(RT.java:390) at clojure.lang.RT.load(RT.java:421) at clojure.lang.RT.load(RT.java:411) ...

Cause: getLastModified() opens the URLConnection's InputStream but does not close it.

Approach: On Stackoverflow [4] there's a discussion on how to close the URLConnection correctly.

On non-Windows operating systems this shouldn't be much of a problem. But on windows this hurts very much, since you can't delete files that are opened by some process.

Patch: clj-1659-v3.patch

Screened by: Alex Miller

[1] http://boot-clj.com/
[2] https://github.com/boot-clj/boot/issues/117
[3] http://file-leak-detector.kohsuke.org/
[4] http://stackoverflow.com/questions/9150200/closing-urlconnection-and-inputstream-correctly

Environment

None

Status

Assignee

Unassigned

Reporter

Ralf Schmitt

Labels

Approval

Ok

Patch

Code

Fix versions

Affects versions

Release 1.6

Priority

Major