-
Notifications
You must be signed in to change notification settings - Fork 311
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
fix: properly close PackageManagers once all dependencies are retrieved #7980
base: main
Are you sure you want to change the base?
Conversation
01b6293
to
1ab360b
Compare
Thanks for spotting the issue and proposing a solution! To get started, there are a bunch of formal issues with this PR. Please do:
|
33b6b62
to
2e145e9
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #7980 +/- ##
============================================
- Coverage 67.01% 66.93% -0.09%
- Complexity 2041 2049 +8
============================================
Files 357 357
Lines 17103 17083 -20
Branches 2443 2455 +12
============================================
- Hits 11462 11434 -28
- Misses 4623 4627 +4
- Partials 1018 1022 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Thanks @netomi for providing this fix. @netomi do you have any explanation why this fix does work? |
I noticed that problem when running ort multiple times locally. Of course randomly but something like every 2-3 runs, the cache would have been corrupted. I found this ticket as it sounds very much like the same problem. The journalWriter is a wrapped BufferedWriter, and not closing that writer (or at least flushing its contents) might explain the problem. When the cache was corrupted it looked like that the last entry was not completely written to the file, so that might be the most likely explanation in this case. Closing resources after they are not used anymore is good practice anyways so I implemented this change. After that change I did not notice a corrupted cache anymore, e.g. I did like 10 run of ORT in a row without noticing the problem anymore. Am I sure that this fixes the problem? No, but I am confident that this fix improves the situation and also gives other PackageManager implementations the chance to close resources before terminating. |
@netomi Quite a while back, we had an issue in ORT that even after the termination of the CLI, ORT's JVM process kept on running. (IIRC this happened due to some code path not existing the thread after catching (or not catching) some exception). Just in case we should have a similar problem again, that could be as well the root cause of the problem. |
ff1323e
to
ba906db
Compare
@@ -19,6 +19,7 @@ | |||
|
|||
package org.ossreviewtoolkit.analyzer | |||
|
|||
import java.io.Closeable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit message: I believe saying "properly close PackageManager instances" is misleading, as before this change package managers were not closeable, so you also couldn't close them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, changed.
@@ -228,5 +228,9 @@ class AnalyzerCommand : OrtCommand( | |||
val issues = analyzerRun.result.getAllIssues().flatMap { it.value } | |||
SeverityStatsPrinter(terminal, resolutionProvider).stats(issues) | |||
.print().conclude(ortConfig.severeIssueThreshold, 2) | |||
|
|||
for (packageManager in info.managedFiles.keys) { | |||
packageManager.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I don't like so much about this approach is that every downstream user of Analyzer.analyze()
has to call close()
itself. I wonder whether a feasible / better approach would be for the respective package manager to override the existing afterResolution()
and close their resources there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand your point, the downside is that the Analyzer is fed with a a list of managedFiles with their associated PackageManager. Thus when the Analyzer would close the PackageManagers after it has finished analysis, the caller would not be able to use the package managers anymore in a safe way as they are already closed. This transfer of ownership would have to be documented imho, but I am indifferent where the closing should happen, as long it happens ofc :-)
@@ -0,0 +1,20 @@ | |||
<?xml version='1.0' encoding='UTF-8'?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The files committed here and below seem like temporary left-overs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, using git add -A is not really a good idea.
Signed-off-by: Thomas Neidhart <[email protected]>
ba906db
to
4081a72
Compare
This fixes #7978 .
This PR makes PackageManagers implement the Closeable interface to be able to close their resources once they are not used anymore (at the end of the analyzer run).
There is a default implementation that does nothing, the maven / gradle package manager override this method in order to close the DiskCache they are using via the MavenSupport class.