Skip to content

Commit

Permalink
Fix large number of open files from java parser
Browse files Browse the repository at this point in the history
There's a file manager that backs each DocletEnvironment. As part of
parsing the docs, a jars from the classpath are loaded into it.  If you
do not close the file manager after you're done with the
DocletEnvironment, they're held onto forever.

Especially due to the `(future)` in orchard.java which parses the docs
for a bunch of classes, this can quickly snowball into the maximum file
limit being reached.  It won't fail in the foreground, but further
attempts to open files will fail.

Closing the file manager is recommended in
https://docs.oracle.com/en/java/javase/11/docs/api/java.compiler/javax/tools/JavaCompiler.html

I attempted to reuse a file manager, but it didn't seem to work
correctly between invocations.  Presumably because of compiler state or
something.
  • Loading branch information
SevereOverfl0w committed Jun 24, 2020
1 parent 9064515 commit af113e3
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/orchard/java/parser.clj
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,17 @@
{:pre [(symbol? klass)]}
(try
(when-let [path (source-path klass)]
(when-let [root (parse-java path (module-name klass))]
(assoc (->> (.getIncludedElements ^DocletEnvironment root)
(filter #(#{ElementKind/CLASS
ElementKind/INTERFACE
ElementKind/ENUM}
(.getKind ^Element %)))
(map #(parse-info % root))
(filter #(= klass (:class %)))
(first))
:file path
:path (.getPath (io/resource path)))))
(when-let [^DocletEnvironment root (parse-java path (module-name klass))]
(try
(assoc (->> (.getIncludedElements root)
(filter #(#{ElementKind/CLASS
ElementKind/INTERFACE
ElementKind/ENUM}
(.getKind ^Element %)))
(map #(parse-info % root))
(filter #(= klass (:class %)))
(first))
:file path
:path (.getPath (io/resource path)))
(finally (.close (.getJavaFileManager root))))))
(catch Throwable _)))

0 comments on commit af113e3

Please sign in to comment.