-
Notifications
You must be signed in to change notification settings - Fork 640
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
File Handle Leak in SearchFiles demo and LargeInputFST test code #615
Comments
Thanks for the report. Technically, this is a duplicate of #265. We haven't yet reviewed the Lucene.NET is (for the most part) a line-by-line port of Lucene 4.8.0. As such, we carried over many of the gaps between Java and .NET. One such gap is that in Java the Closable interface inherits the AutoCloseable interface, which can be configured to automatically be cleaned up. We haven't yet researched whether Lucene is configured with that option enabled, but suspect that is the reason why the code doesn't explicitly call Given this fact, there are likely lots of places where there are missing calls to Note there is at least 1 known place where the call to It sounds like CodeQL can be utilized to speed up the process of locating them. My suggestion would be to submit a separate commit for each of the issues you found, and break them down into multiple PRs in some sensible way, so we can review and test them thoroughly chunk by chunk |
Thank you for all the useful links. From the current analysis it doesn't seem like all the alerts that have been raised could be bugs. For example, "MemoryStream" instances in the code do not necessarily have to be disposed since they would be garbage collected without causing any resource leaks. I will raise PR's for the bugs and submit the fixes as part of separate commits. |
Looking at the two files listed, one of them is in Demo, and the other is in unit tests. The Demo one still matches latest Lucene. (I can't find the other test file quickly in latest Lucene, might have been renamed.) The latter isn't even referenced in Lucene.NET anyways and probably just serves as example code. I think these cases can be fixed so I'll leave this open, but I don't think this is high priority. As @NightOwl888 noted, #265 would serve as a good review of this solution-wide. |
Missing dispose calls can also be found by the NETAnalyzers that integrate into your local dev env. Are you interested in activating them in the whole solution? Seems like there are a lot more missing dispose calls - 28 CA2000 warnings in the main project "Lucene.Net". |
Hi,
I am new to the Lucenenet project. While investigating this project, I found this bug related to a file handle leak.
Location: https://github.com/apache/lucenenet/blob/master/src/Lucene.Net.Demo/SearchFiles.cs#L117
Bug: The "input" variable can point to a FileStream that is never disposed.
Another example:
Location: https://github.com/apache/lucenenet/blob/master/src/Lucene.Net.Tests.Suggest/Suggest/Fst/LargeInputFST.cs#L45
Bug: The "reader" variable points to a FileStream that is never disposed.
I was also wondering if such kind of leaks related to IDisposables exist in the code base. Running an existing CodeQL (static analysis tool) query for detecting local un-disposed objects in the code, I observed 45 alerts being generated for the entire codebase. I do not know if all of these 45 alerts are actual leaks or benign alerts.
Could you please share information on ways in which leaks, in general, are currently being prevented in the Lucenenet project (any tools being used or processes in place)?
Thanks in advance!
The text was updated successfully, but these errors were encountered: