Skip to content

Conversation

thecoop
Copy link
Contributor

@thecoop thecoop commented Aug 28, 2025

Most of the remaining ones are in backwards-compatible codecs and the test framework

@thecoop thecoop added the skip-changelog Apply to PRs that don't need a changelog entry, stopping the automated changelog check. label Aug 28, 2025
} else {
IOUtils.deleteFilesIgnoringExceptions(tempDir, sortedFile);
}
tempDir.deleteFile(sortedFile);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exceptions thrown by this should be handled by the method calling this close() method

if (success) {
IOUtils.close(reader, dir);
} else {
IOUtils.closeWhileHandlingException(reader, writer, dir);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new code implicitly calls close() on writer after rollback() has been called, but IndexWriter can handle that

@uschindler
Copy link
Contributor

This one is more complicated than the others. Especially the first file is hard. Why was it possible to remove success without any other code change?

@thecoop
Copy link
Contributor Author

thecoop commented Sep 1, 2025

You mean SortingStrategy? sortedFile was being closed in all situations anyway, but this change makes it throw any exceptions regardless. This is ok because this is only used in hunspell.Dictionary, which iterates through the EntrySorter here.

That loop only exits normally once it gets to the end (returns null), all other possible exits of that loop are through exceptions. The exception will bubble up to the caller, where the try block will call EntrySorter.close. If that throws an exception (which it didn't previously), it'll be added as suppressed to the original exception, so the original behaviour is maintained. The only difference is that an exception while closing the file will be added as suppressed, rather than being thrown away completely.

Copy link
Contributor

This PR has not had activity in the past 2 weeks, labeling it as stale. If the PR is waiting for review, notify the dev@lucene.apache.org list. Thank you for your contribution!

Copy link
Contributor

@uschindler uschindler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really a hard one. The easy ones are perfectly fine, the other ones are partly hard to read, biut with github side-by-side view its manageable:

  • Simple ones are fine
  • SegmentCoreReaders is more complex than before (nested try blocks). Maybe revert that one and keep the old success pattern here?
  • FreeTextSuggester is not understandable by me :-(
  • TestSimpleServer is fine, but you need to notice the try (socket) on top!

} finally {
try {
if (success) {
IOUtils.close(reader, dir);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It helps to note here that reader and dir are closed whatever the outcome. This means that both those can be moved to try-with-resources when they are created, so they are always closed.

Previously, writer was only closed explicitly if an exception was thrown. If it completed normally, only rollback() was called. But IndexWriter checks for close being called after rollback, and makes sure that it is only closed once. So this means that writer can also be in a try-with-resources when it is created, as the extra implicit close at the end of the outer try is a no-op if rollback is called, and closes it if an exception is thrown (which is what the previous code also did).

In terms of live-ness, the try for the finally block the IOUtils.rm runs in has increased in scope to include creating the Document, FieldType, and IndexWriter at the start. Previously, if IndexWriter threw an exception, the directory wouldn't be cleaned up. This is now the case, so it won't leak tempIndexPath if IndexWriter throws an exception

@github-actions github-actions bot removed the Stale label Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module:analysis module:core/index module:core/store module:facet module:replicator module:suggest skip-changelog Apply to PRs that don't need a changelog entry, stopping the automated changelog check.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants