Skip to content

Fix ILVerifier holding files open #89127

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

Conversation

mrvoorhe
Copy link
Contributor

There were a couple things to fix

  1. PEReader implements IDisposable and needs to be disposed. Not least because it is managing the lifetime of the streams opened by File.OpenRead calls inside ILVerifier

  2. In order to dispose of of the pereaders, add IDisposable to ILVerifier and add a using to the caller that creates a new instance.

(1) and (2) fix the issues with files being held open.

While looking at the code, I didn't see a reason why TryLoadAssemblyFromFolder couldn't check the _assemblyCache before creating a opening a new stream and creating a new pereader. I don't think this was causing any issues. It just seemed like a harmless just-in-case change.

There were a couple things to fix

1) `PEReader` implements `IDisposable` and needs to be disposed.  Not least because it is managing the lifetime of the streams opened by `File.OpenRead` calls inside `ILVerifier`

2) In order to dispose of of the pereaders, add `IDisposable` to `ILVerifier` and add a `using` to the caller that creates a new instance.

(1) and (2) fix the issues with files being held open.

While looking at the code, I didn't see a reason why `TryLoadAssemblyFromFolder` couldn't check the `_assemblyCache` before creating a opening a new stream and creating a new pereader.  I don't think this was causing any issues.  It just seemed like a harmless just-in-case change.
@mrvoorhe mrvoorhe requested a review from marek-safar as a code owner July 18, 2023 20:49
@ghost ghost added needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners linkable-framework Issues associated with delivering a linker friendly framework community-contribution Indicates that the PR has been added by a community member labels Jul 18, 2023
@ghost
Copy link

ghost commented Jul 18, 2023

Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @sbomer, @joperezr, @marek-safar
See info in area-owners.md if you want to be subscribed.

Issue Details

There were a couple things to fix

  1. PEReader implements IDisposable and needs to be disposed. Not least because it is managing the lifetime of the streams opened by File.OpenRead calls inside ILVerifier

  2. In order to dispose of of the pereaders, add IDisposable to ILVerifier and add a using to the caller that creates a new instance.

(1) and (2) fix the issues with files being held open.

While looking at the code, I didn't see a reason why TryLoadAssemblyFromFolder couldn't check the _assemblyCache before creating a opening a new stream and creating a new pereader. I don't think this was causing any issues. It just seemed like a harmless just-in-case change.

Author: mrvoorhe
Assignees: -
Labels:

linkable-framework, needs-area-label

Milestone: -

@vitek-karas
Copy link
Member

Test failures are unrelated.

@vitek-karas vitek-karas merged commit 14036c5 into dotnet:main Jul 19, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Aug 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
community-contribution Indicates that the PR has been added by a community member linkable-framework Issues associated with delivering a linker friendly framework needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants