dotnet / dotnet/sdk

dotnetup GC: show which process is locking files that can't be deleted

Open
#53,468 1 comment 0 reactions 0 assignees View on GitHub
Area-dotnetup
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

## Summary

When dotnetup's garbage collector tries to delete an unreferenced runtime subcomponent directory and gets an `Access denied` error, the warning message doesn't indicate which process is holding the file lock:

```
Warning: Could not delete 'shared/Microsoft.NETCore.App/8.0.24': Access to the path 'clrjit.dll' is denied.
```

It would be helpful to include the process name and PID in the warning so users understand why cleanup is deferred.

## Proposed behavior

```
Warning: Could not delete 'shared/Microsoft.NETCore.App/8.0.24': 'clrjit.dll' is locked by GlobalSecureAccessClient (PID 17236). Will retry on next garbage collection.
```

## Implementation notes

- On Windows, use the **Restart Manager API** (`RmStartSession`/`RmRegisterResources`/`RmGetList`) to efficiently find the locking process. The P/Invoke is ~50 lines.
- On Linux/macOS, parse `/proc/*/maps` or use `lsof`.
- No retry logic needed — the next GC run will attempt cleanup again.
- The relevant code is in `GarbageCollector.cs` around line 183.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.