Skip to content

skip the test when dotnet.exe is locked - #66196

Merged
danmoseley merged 4 commits into
dotnet:mainfrom
adamsitnik:issue65820
Apr 27, 2022
Merged

danmoseley merged 4 commits into
dotnet:mainfrom
adamsitnik:issue65820

Conversation

@adamsitnik

@adamsitnik adamsitnik commented Mar 4, 2022 •

Copy link
Copy Markdown
Member

I've tried to repro #65820 and of course I've failed to do that.

However, I was able to repro the same exception by opening the dotnet.exe for writing with exclusive file access before starting the process:

ProcessStartInfo startInfo = new ProcessStartInfo()
{
    FileName = @"C:\Program Files\dotnet\dotnet2.exe",
    Arguments = "--info",
    RedirectStandardOutput = true, // avoid visible output
    UseShellExecute = false
};

var fs = new FileStream(startInfo.FileName, FileMode.Open, FileAccess.ReadWrite, FileShare.None, 4096, false);
Console.WriteLine(fs.Length);

using Process dotnet = Process.Start(startInfo);
dotnet.WaitForExit();
fs.Dispose();

In the perfect world, I would enable ETW logging for file events on the CI machines and find out who is locking the file and why, but in my opinion it would take more time than it's worth it. I think that we can just skip this test when dotnet.exe is locked.

fixes #65820

@adamsitnik adamsitnik added area-System.IO test-enhancement Improvements of test source code labels Mar 4, 2022
@adamsitnik adamsitnik added this to the 7.0.0 milestone Mar 4, 2022
@adamsitnik
adamsitnik requested review from danmoseley and jozkee March 4, 2022 15:22
@ghost ghost assigned adamsitnik Mar 4, 2022
@ghost

ghost commented Mar 4, 2022

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

I've tried to repro #65820 and of course I've failed to do that.

However, I was able to repro the same exception by opening the dotnet.exe for writing with exclusive file access before starting the process:

ProcessStartInfo startInfo = new ProcessStartInfo()
{
    FileName = @"C:\Program Files\dotnet\dotnet2.exe",
    Arguments = "--info",
    RedirectStandardOutput = true, // avoid visible output
    UseShellExecute = false
};

var fs = new FileStream(startInfo.FileName, FileMode.Open, FileAccess.ReadWrite, FileShare.None, 4096, false);
Console.WriteLine(fs.Length);

using Process dotnet = Process.Start(startInfo);
dotnet.WaitForExit();
fs.Dispose();

In the perfect world, I would enable ETW logging for file events on the CI machines and find out who is locking the file and why, but in my opinion it would take more time than it's worth it. So to tell the long story short I think that we can just skip this test when dotnet.exe is locked.

fixes #65820

Author: adamsitnik
Assignees: -
Labels:

area-System.IO, test-enhancement

Milestone: 7.0.0

@adamsitnik

Copy link
Copy Markdown
Member Author

/azp list

@azure-pipelines

Copy link
Copy Markdown

@adamsitnik

Copy link
Copy Markdown
Member Author

/azp run runtime-libraries-coreclr outerloop-windows

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@adamsitnik

Copy link
Copy Markdown
Member Author

@danmoseley @jozkee ping

{
hasStarted = p.Start();
}
catch (Win32Exception ex) when (ex.NativeErrorCode == ERROR_SHARING_VIOLATION)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this covers "The process cannot access the file because it is being used by another process.", Does it cover "Access is denied." as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jozkee good catch! I've extended the current logic that was granting access to the executable file to also provide access to the working directory. I hope it fixes the issue. PTAL

@danmoseley

Copy link
Copy Markdown
Contributor

Another approach could be to add this utility somewhere, although I think would not work for very transient locks as ETW would.

https://github.com/dotnet/msbuild/blob/6a79376cc50e5f0d829475adc418e7078776ccb7/src/Tasks/LockCheck.cs#L17

@adamsitnik
adamsitnik requested a review from jozkee April 25, 2022 17:23
@adamsitnik

Copy link
Copy Markdown
Member Author

/azp run runtime-libraries-coreclr outerloop-windows

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@adamsitnik

Copy link
Copy Markdown
Member Author

/azp run runtime-libraries-coreclr outerloop-windows

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@jozkee jozkee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

@danmoseley

Copy link
Copy Markdown
Contributor

inner loop failure is #67948
outer loop failures are clearly not related - i'll let build monitor deal with them.

@danmoseley
danmoseley merged commit fc9a75c into dotnet:main Apr 27, 2022
@adamsitnik
adamsitnik deleted the issue65820 branch April 29, 2022 08:36
@ghost ghost locked as resolved and limited conversation to collaborators May 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.IO test-enhancement Improvements of test source code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test failure System.Diagnostics.Tests.ProcessStartInfoTests.TestUserCredentialsPropertiesOnWindows

3 participants