Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispose of some disposables, #265, #615 #1074

Merged
merged 7 commits into from
Dec 26, 2024
Merged

Conversation

paulirwin
Copy link
Contributor

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a change, please open an issue to discuss the change or find an existing issue.

Disposes of some IDisposable objects that are not properly cleaned up.

Fixes #615
Partial #265

Description

This adds using statements to clean up some disposable objects where it's possible to do so, after a review of our codebase with CA2000 code analysis warnings on, where the objects were determined to not "leak" via fields, return values, or the like. This also fixes two FileStream leaks in demo code, #615.

Note that CA2000 is way too noisy to leave on, as there are literally hundreds of "violations" that would make our code a mess with #pragma suppressions. The Java upstream code is perhaps a little loose with keeping track of ICloseable lifetimes, but we have to match that in most cases. The cases fixed here were just ones where the object lifetime did not escape the method and it was safe to do so.

Copy link
Contributor

@NightOwl888 NightOwl888 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR.

I agree that keeping CA2000 on would not be a great idea. That being said, some of these had real underlying issues, but others also inadvertently cause Dispose() to be called multiple times on the underlying stream. What is your estimate on how thorough this review is?

IDisposable is a leaky abstraction, so when it is implemented in a base class all of the subclasses automatically inherit it even if they don't require it. I think the Lucene team is pretty thorough about declaring most of them properly, but there are some exceptions to this. It would be good to catch those exceptions before the release, if possible.

src/Lucene.Net.Analysis.Kuromoji/Dict/BinaryDictionary.cs Outdated Show resolved Hide resolved
src/Lucene.Net/Util/Constants.cs Show resolved Hide resolved
src/Lucene.Net/Store/LockVerifyServer.cs Outdated Show resolved Hide resolved
src/Lucene.Net/Store/LockStressTest.cs Outdated Show resolved Hide resolved
src/Lucene.Net.Tests.Suggest/Suggest/Fst/LargeInputFST.cs Outdated Show resolved Hide resolved
@paulirwin paulirwin merged commit d96dc9e into apache:master Dec 26, 2024
267 checks passed
@paulirwin paulirwin deleted the issue/265 branch December 26, 2024 15:43
@paulirwin paulirwin restored the issue/265 branch December 26, 2024 15:43
@paulirwin paulirwin deleted the issue/265 branch December 26, 2024 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File Handle Leak in SearchFiles demo and LargeInputFST test code
2 participants