Richard Zowalla created OPENNLP-1948:
----------------------------------------
Summary: File handles opened by MarkableFileInputStreamFactory and
the Leipzig reader are released only at GC
Key: OPENNLP-1948
URL: https://issues.apache.org/jira/browse/OPENNLP-1948
Project: OpenNLP
Issue Type: Bug
Reporter: Richard Zowalla
* {{MarkableFileInputStream}} \(opennlp\-formats {{opennlp.tools.util}}\) wraps
a {{FileInputStream}} it creates itself but has no {{close\(\)}} override.
{{InputStream.close\(\)}} is a no\-op, so closing the stream never closes the
file.
* {{LeipzigLanguageSampleStream.java:70}}: {{\(int\)
Files.lines\(sentencesFile.toPath\(\)\).count\(\)}}. The stream from
{{Files.lines}} is never closed.
* {{PlainTextByLineStream.reset\(\)}} \({{opennlp\-api}}, line 73\) creates a
new reader without closing the previous one, so every reset leaks one handle.
Impact: long\-running training or cross\-validation over many files runs into
"Too many open files". On Windows, files stay locked.
Both leaks also exist on 2.x \({{opennlp\-tools}}\).
_Fix:_
\* Override {{close\(\)}} in {{MarkableFileInputStream}}.
\* Use try\-with\-resources around {{Files.lines}}.
\* Close {{in}} in {{reset\(\)}} before reassigning it.
PR #1279 \(OPENNLP\-1933\) contains fixes for the first two; they should move
here.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)