-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Include list of processes that have the file open in IOException message on Windows #109927
Comments
Tagging subscribers to this area: @dotnet/area-system-io |
Does it need an additional syscall that has potential race condition issue? |
Yes, it needs additional syscalls. The process that caused the error may have closed the file already; additional processes may have opened the file after the error; and some of the listed processes may have opened the file with file sharing flags that did not conflict with the access that failed. I'm not sure whether Restart Manager works with remote files (UNC paths). Regarding security concerns: applications can already call the Restart Manager API directly so this doesn't let applications do anything new. Risks:
|
All valid points. Hence the suggestion to
Also, it is understood that the information might not be precise. The error message Roslyn displays is "it may be locked by MyApp (12345)". |
NuGet could use this: NuGet/Home#13937 |
Assigned to @adamsitnik for triage. |
I like the idea of extending the message provided by My main concern is that it's not just a matter of calling one sys-call. We would need to call at least four different sys-calls:
And there seems to be a limit in regard to the number of opened sessions: Of course we could handle reaching the limit by not providing the extra information. And these sys-calls are available on all Windows that we support (Vista+, Server 2008+). @jkotas @stephentoub do we provide any extra information similar to this for any other exceptions in .NET? Would doing that be against any guidance we have? |
I would be worried about overhead and reliability of providing this additional information.
|
@jkotas Would this mitigate your concerns?
|
Somewhat. AppContext switches are process global. They do not work when different parts of the app want them configured differently. We tend to prefer APIs. AppContext switches are solution of last resort. |
In scenarios like msbuild, it'd actually be beneficial if the host (msbuild) set this flag for all exceptions that occur within the build, so that individual tasks don't need to be updated with extra logic. |
Description
Windows's Restart Manage allows to query for process that have a file open:
https://learn.microsoft.com/en-us/windows/win32/api/restartmanager/nf-restartmanager-rmgetlist
This Win32 API is used by msbuild and Roslyn to provide better error message to users, when a build task or the compiler attempts to write to a file that's locked by another process. Having this info in the error message makes it easier to diagnose intermittent file locking issues (e.g. on CI).
The proposal is to move this code to runtime and automatically list process names and ids in the message of
System.IO.IOException
(The process cannot access the file ... because it is being used by another process.
). Possibly allow controlling it by an AppContext switch, so that a host app could decide whether or not to include this information in all instances of IOException caused by access to a file used by another process.Reproduction Steps
n/a
Expected behavior
The message of
System.IO.IOException
isThe process cannot access the file ... because it is being used by another process. The file may be locked by <app name> (<pid>), <app name> (<pid>), ...
Actual behavior
The message of
System.IO.IOException
does not include process information:The process cannot access the file ... because it is being used by another process.
Regression?
no
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: