Repository navigation
OPENNLP-1948: Release file handles by MarkableFileInputStreamFactory and the Leipzig reader on close and reset - #1297
Merged
mawiesne merged 1 commit intoSep 16, 2026
Conversation
MarkableFileInputStream closes the file it opened, the Leipzig line count closes its stream, and PlainTextByLineStream.reset closes the previous reader before opening the next one. Contract tests cover each. The manual states the reset rule for InputStreamFactory implementations.
krickert
force-pushed
the
OPENNLP-1948-file-handle-leaks
branch
from
September 16, 2026 02:30
6944822 to
bf7c5aa
Compare
rzo1
approved these changes
Sep 16, 2026
mawiesne
marked this pull request as ready for review
September 16, 2026 05:38
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three readers kept a file descriptor open until the garbage collector ran. On main, 200 open-and-close cycles of
MarkableFileInputStreamFactory.createInputStream()left 200 descriptors open. Long training or cross-validation runs over many files can run into "Too many open files", and on Windows the files stay locked.Changes
MarkableFileInputStream(opennlp-formats,opennlp.tools.util):close()now closes theFileInputStreamthe class opened. Before, the inheritedInputStream.close()was a no-op, so closing the stream, or a reader wrapped around it, never closed the file. Closing twice has no effect.LeipzigLanguageSampleStream.LeipzigSentencesStream: theFiles.linesstream used to count the lines of a sentence file is closed after counting. Before, it was never closed.PlainTextByLineStream.reset()(opennlp-api): the previous reader is closed before a new one is created. Before, each reset opened a new input stream and dropped the old one unclosed, so every pass over aMarkableFileInputStreamFactoryleaked one descriptor.No behavior changes beyond releasing the descriptors: the bytes read, the lines returned, and the samples produced are the same.
Tests
MarkableFileInputStreamTest(new): mark and reset, reset without mark rejected, a read afterclose()fails, close twice accepted, and closing aBufferedReaderover the stream closes the file. The two close tests fail on main.PlainTextByLineStreamTest: a factory hands out streams that recordclose(); after eachreset()the earlier stream is closed and the current one open, andclose()closes the last one. Fails on main.LeipzigLanguageSampleStreamTest: the sample directory is read a second time with the same result; the descriptor released by the fix is not observable portably, so the test pins the behavior around it.Full runs with checkstyle,
-Dopennlp.forkCount=1: opennlp-api 385, opennlp-formats 363, opennlp-tools 419 tests, 0 failures.Manual
introduction.xml: a new section "Closing and resetting input streams" states thatreset()closes the previous reader, so anInputStreamFactorymust hand out a fresh stream for each pass, and names the two other fixes.Release note and backport
All three leaks exist on 2.x (
opennlp-tools). This change is meant for a release note and a backport to the 2.x line. The same fixes for the first two leaks are on the #1279 branch (OPENNLP-1933) and come off it once this one is in.OPENNLP-1948