Skip to content
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

HostWriter: ResourceUpdate fails non-deterministically #3832

Closed
DamianEdwards opened this issue Jun 27, 2019 · 82 comments · Fixed by #32347
Closed

HostWriter: ResourceUpdate fails non-deterministically #3832

DamianEdwards opened this issue Jun 27, 2019 · 82 comments · Fixed by #32347
Assignees
Labels
area-HostModel Microsoft.NET.HostModel issues
Milestone

Comments

@DamianEdwards
Copy link
Member

Steps to reproduce

  1. Create a new web app: dotnet new webapp
  2. Repeatedly build the app from the CLI with no changes: dotnet build

Expected behavior

No errors

Actual behavior

Randomly see the following error (twice in the last 20 builds just now):

C:\src\local\BuildPerf\WebApp3.0> dotnet build                                                                                     Microsoft (R) Build Engine version 16.3.0-preview-19325-02+eca7818b1 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 19.81 ms for C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj.
  You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: The "CreateAppHost" task failed unexpectedly. [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: Microsoft.NET.Build.Tasks.ResourceUpdater+HResultException: 8007006E [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResourceUpdater.ThrowExceptionForLastWin32Error() in /_/src/Tasks/Microsoft.NET.Build.Tasks/ResourceUpdater.cs:line 436 [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResourceUpdater.Update() in /_/src/Tasks/Microsoft.NET.Build.Tasks/ResourceUpdater.cs:line 324 [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018:    at Microsoft.NET.Build.Tasks.AppHost.Create(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String intermediateAssembly, Logger log) in /_/src/Tasks/Microsoft.NET.Build.Tasks/AppHost.cs:line 82 [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018:    at Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore() in /_/src/Tasks/Microsoft.NET.Build.Tasks/CreateAppHost.cs:line 38 [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() in /_/src/Tasks/Common/TaskBase.cs:line 38 [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]

Build FAILED.

C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: The "CreateAppHost" task failed unexpectedly. [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018: Microsoft.NET.Build.Tasks.ResourceUpdater+HResultException: 8007006E [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResourceUpdater.ThrowExceptionForLastWin32Error() in /_/src/Tasks/Microsoft.NET.Build.Tasks/ResourceUpdater.cs:line 436 [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResourceUpdater.Update() in /_/src/Tasks/Microsoft.NET.Build.Tasks/ResourceUpdater.cs:line 324 [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018:    at Microsoft.NET.Build.Tasks.AppHost.Create(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String intermediateAssembly, Logger log) in /_/src/Tasks/Microsoft.NET.Build.Tasks/AppHost.cs:line 82 [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018:    at Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore() in /_/src/Tasks/Microsoft.NET.Build.Tasks/CreateAppHost.cs:line 38 [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() in /_/src/Tasks/Common/TaskBase.cs:line 38 [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(358,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\src\local\BuildPerf\WebApp3.0\WebApp3.0.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:02.58

Environment data

dotnet --info output:

.NET Core SDK (reflecting any global.json):
 Version:   3.0.100-preview7-012649
 Commit:    3f4ab7f5c5

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100-preview7-012649\

Host (useful for support):
  Version: 3.0.0-preview7-27826-04
  Commit:  5c4d829254

.NET Core SDKs installed:
  2.1.700-preview-009618 [C:\Program Files\dotnet\sdk]
  2.1.800-preview-009677 [C:\Program Files\dotnet\sdk]
  2.1.800-preview-009696 [C:\Program Files\dotnet\sdk]
  2.2.204 [C:\Program Files\dotnet\sdk]
  3.0.100-preview7-012649 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0-preview7.19326.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0-preview7-27826-04 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0-preview7-27826-04 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
@livarcocc
Copy link
Contributor

@peterhuene can you take a look?

@peterhuene peterhuene self-assigned this Jun 27, 2019
@peterhuene
Copy link

0x8007006E is cannot open the file specified. Not entirely sure if that's because it doesn't exist or a sharing violation. My guess would be on the latter since it's intermittent (perhaps something external to the build is interfering?).

@peterhuene
Copy link

We have a lot of tests that create and customize the apphost on Windows and I haven't seen flaky CI with this. I'll attempt to repro it.

@livarcocc
Copy link
Contributor

Anti-virus?

@peterhuene
Copy link

I ran dotnet build 100 times in my VM with 3.0.100-preview7-012687 and had no failures.

@DamianEdwards are you seeing this on a particular machine or multiple machines?

@DamianEdwards
Copy link
Member Author

@peterhuene was seeing this on only one machine so far, but haven't tried to repro it on my other machine.

@peterhuene
Copy link

@DamianEdwards I'm still not able to reproduce this.

The API call is EndUpdateResource and the error code is 110 (ERROR_OPEN_FAILED). It seems that some antivirus software may interfere with this API.

As I don't have any MSIT-controlled Windows machines (and it's been a decade since I last did), I don't know what we're using for antivirus on corpnet these days.

Would it be possible to check if its the real-time protection of the antivirus software that's interfering with the build?

@peterhuene
Copy link

I'm updating the CreateAppHost task to be more resilient to a temporarily locked intermediate apphost, like MSBuild handles file copying. Hopefully this will help alleviate this problem.

peterhuene referenced this issue in peterhuene/sdk Jul 26, 2019
This commit implements a parameterized retry count for creating the apphost.

Like the `Copy` task from MSBuild, the `CreateAppHost` task now takes a
parameter to specify the number of retries and the delay between retries (in
milliseconds) to perform if the creation fails.

This should help alleviate build failures when external processes are locking
the intermediate apphost during a build (especially on Windows).

Fixes devdiv#950462.
Fixes dotnet/cli#11650.
peterhuene referenced this issue in peterhuene/sdk Jul 30, 2019
This commit implements a parameterized retry count for creating the apphost.

Like the `Copy` task from MSBuild, the `CreateAppHost` task now takes a
parameter to specify the number of retries and the delay between retries (in
milliseconds) to perform if the creation fails.

This should help alleviate build failures when external processes are locking
the intermediate apphost during a build (especially on Windows).

Fixes devdiv#950462.
Fixes dotnet/cli#11650.
@wli3
Copy link

wli3 commented Aug 1, 2019

I have a repro too during app building on blazor server app, but not consistent. I ran git clean -fxd. and open the sln with VS then F5.

Severity	Code	Description	Project	File	Line	Suppression State
Error	MSB4018	The "CreateAppHost" task failed unexpectedly.
System.IO.IOException: The process cannot access the file 'C:\work\appbuilding\emojisearch.blazor\emojisearch.blazor\obj\Debug\netcoreapp3.0\emojisearch.blazor.exe' because it is being used by another process.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
   at System.IO.File.OpenFile(String path, FileAccess access, SafeFileHandle& handle)
   at System.IO.File.SetLastWriteTimeUtc(String path, DateTime lastWriteTimeUtc)
   at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResorcesFrom)
   at Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore() in /_/src/Tasks/Microsoft.NET.Build.Tasks/CreateAppHost.cs:line 35
   at Microsoft.NET.Build.Tasks.TaskBase.Execute() in /_/src/Tasks/Common/TaskBase.cs:line 47
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()	emojisearch.blazor	C:\Program Files\dotnet\sdk\3.0.100-preview9-013654\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets	359	

@peterhuene
Copy link

Would it be possible to use procmon to see if we can figure out who is opening the file? I've never been able to reproduce the issue in a VM.

@wli3
Copy link

wli3 commented Aug 1, 2019

good point, let me try several times more

peterhuene referenced this issue in peterhuene/sdk Aug 2, 2019
This commit implements a parameterized retry count for creating the apphost.

Like the `Copy` task from MSBuild, the `CreateAppHost` task now takes a
parameter to specify the number of retries and the delay between retries (in
milliseconds) to perform if the creation fails.

This should help alleviate build failures when external processes are locking
the intermediate apphost during a build (especially on Windows).

Fixes devdiv#950462.
Fixes dotnet/cli#11650.
@peterhuene
Copy link

For preview 9, we'll retry the apphost creation as a mitigation for these file locking issues.

I'm going to leave this issue open for now to see if we can get some idea of which external process is locking the apphost.

@wli3
Copy link

wli3 commented Aug 7, 2019

Spend another half of an hour trying to repro, see once again, but forget to open procmon :( start to think it is anti virus scan -- once it is scanned once, it no longer does that anymore.

@swaroop-sridhar
Copy link
Contributor

@peterhuene I looked a bit more at the ResourceUpdater code in HostModel -- wrt whether/where retries should be added to ResouceUpdater code.

Looks like there are only two places where a file is opened:

Both the above functions take in a path and obtain a HANDLE to it. So, it is reasonable that we have retries around these calls to protect against an AV locking the apphost file. The remaining functions operate on the handles obtained above, which should have secured the file open for use. So, we should not need retries around them.

In particular, in the callstack described above, we see that the Kernel32.EndUpdateResource() failed on a previously open apphost -- after we've checked that the handle is non-zero.

So, I don't think adding retries is the correct fix in this case.

@swaroop-sridhar
Copy link
Contributor

There is one scenario I can see where we may end up in this case: If we call ResourceUpdater.Update() twice.

The Update() function releases the SafeHandle whether or not it succeeds, but it does not zero out the handle. So, it is possible that we have a stale handle that passes the SafeUpdateHandle.IsInvalid test, but then ends up throwing the error.

@swaroop-sridhar
Copy link
Contributor

The error codes for lock-violation is 21 (file) and 6C (disk).
The 6E error code is for a file that cannot be open (which agrees with the theory that the handle is invalid).

@swaroop-sridhar
Copy link
Contributor

@peterhuene @wli3
I've submitted dotnet/core-setup#7665 for retrying resource-update in HostModel. But I don't think it'll fix this issue.

@nguerrera
Copy link
Contributor

Reopened based on discussion above suggesting there's still something else here

@UweKeim
Copy link

UweKeim commented Aug 22, 2019

I'm getting this/a similar error with an ASP.NET Core 3 Preview-7 project, when I first opened it with Preview-8 in Visual Studio 2019:

1>------ Rebuild All started: Project: TechmemeRiver, Configuration: Release Any CPU ------
1>You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
1>
1>Bundler: Cleaning output from bundleconfig.json
1>Bundler: Done cleaning output file from bundleconfig.json
1>
1>Bundler: Begin processing bundleconfig.json
1>	Minified wwwroot/css/site.min.css
1>	Minified wwwroot/js/site.min.js
1>Bundler: Done processing bundleconfig.json
1>C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(359,5): error MSB4018: The "CreateAppHost" task failed unexpectedly.
1>C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(359,5): error MSB4018: Microsoft.NET.HostModel.ResourceUpdater+HResultException: 80070005
1>C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(359,5): error MSB4018:    at Microsoft.NET.HostModel.ResourceUpdater.Update()
1>C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(359,5): error MSB4018:    at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResorcesFrom)
1>C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(359,5): error MSB4018:    at Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore() in /_/src/Tasks/Microsoft.NET.Build.Tasks/CreateAppHost.cs:line 35
1>C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(359,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() in /_/src/Tasks/Common/TaskBase.cs:line 47
1>C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(359,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
1>C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(359,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
1>Done building project "TechmemeRiver.csproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Edit 1:

After doing a "Clean" and "Rebuild", the error does not occur anymore:

1>------ Rebuild All started: Project: TechmemeRiver, Configuration: Release Any CPU ------
1>You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
1>
1>Bundler: Cleaning output from bundleconfig.json
1>Bundler: Done cleaning output file from bundleconfig.json
1>
1>Bundler: Begin processing bundleconfig.json
1>	Minified wwwroot/css/site.min.css
1>	Minified wwwroot/js/site.min.js
1>Bundler: Done processing bundleconfig.json
1>TechmemeRiver -> E:\Dropbox\Beruf\Prog\TechmemeRiver\Source\TechmemeRiver\bin\Release\netcoreapp3.0\TechmemeRiver.dll
1>TechmemeRiver -> E:\Dropbox\Beruf\Prog\TechmemeRiver\Source\TechmemeRiver\bin\Release\netcoreapp3.0\TechmemeRiver.Views.dll
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

I hope, it stays this way.

@livarcocc
Copy link
Contributor

@peterhuene any ideas?

@peterhuene
Copy link

peterhuene commented Aug 22, 2019

No new theories other than something like an antivirus program is interfering with writing out the resources. I've been unable to reproduce at all, but I don't use any such programs that might interfere in this manner.

The above is a generic access denied error. I still believe that retry at the point of resource updater interaction in HostWriter will help mitigate the issue.

Ultimately I hope a future version of the SDK opens the apphost just once for customization, but that would require getting rid of the resource API usage (something we want to do to increase supported platforms for the operation anyway).

@peterhuene peterhuene removed their assignment Sep 10, 2019
@Kurira
Copy link

Kurira commented Sep 28, 2019

This still happens randomly on release bits. Usually on build either through vs or if dotnet tool tries to compile assembly. Never happened twice in a row though.

@nguerrera
Copy link
Contributor

I didn’t realize there was 500 retries possible.

@swaroop-sridhar
Copy link
Contributor

swaroop-sridhar commented Feb 15, 2020

Yes it is 500 retries with 100 ms wait between each.
So, a real failure will take about a minute to fail.

@nguerrera
Copy link
Contributor

Ok then it makes sense to filter the known useless-to-retry cases

@nguerrera
Copy link
Contributor

I think I’m OK with this plan if its lifecycle is limited to past releases and we do the better thing in 5

@swaroop-sridhar
Copy link
Contributor

That's my thought @nguerrera.
I don't like the fix -- but I'm not sure what else can be done that's small enough to take for servicing.
I did spend quite some time trying to repro the failure -- to obtain a dump to see how the other HResults were obtained, but no luck with that.

@swaroop-sridhar
Copy link
Contributor

The other option is to retry after the known reported cases of 0x6E (Open failed) and 0x05 (Acces Denied).

swaroop-sridhar added a commit to swaroop-sridhar/runtime that referenced this issue Feb 18, 2020
This change attempts to fix a non-deterministic customer reported failure.

Several customers have observed failure during resource update when the HostModel updates the AppHost (to transfer resources from the managed app).
The failure is not detereminisitc, not reproducible on our machines, and depends on specific computers/software running.
This indicates interference by other software while the HostWriter is updating the AppHost.

The current implementation retries the resource update if an update because the device or drive is locked (say by an antivurus) HRESULT 0x21 and 0x6C.
However, the failures reported have errors 0x5 (Access violation) and 0x6# (Open failed).
Windows/Defender team said that file-locking with these error-codes is not expected.
However, different AVs work differently about examining files.

We believe that the correct fix for this issue is to complete:

To implement dotnet#3828 and dotnet#3829
Ship AppHost with an extension/permissions not indicating an executable.
However the above is a fairly large change for servicing .net core 3.1.

So, this change implements a simpler fix intended for servicing 3.1 branch:
Always retry the resource-update on Win32 error, unless the failure is a knwon irrecoverable code
(listed a few error codes relevent to File IO).

This change may cause unnecessary retries on legitimate failures (about 50 seconds).
But such cases are rare, because the SDK supplies the apphost, and the HostModel itself creates the file to update.

Fixes dotnet#3832
swaroop-sridhar added a commit that referenced this issue Feb 19, 2020
This change attempts to fix a non-deterministic customer reported failure.

Several customers have observed failure during resource update when the HostModel updates the AppHost (to transfer resources from the managed app).
The failure is not detereminisitc, not reproducible on our machines, and depends on specific computers/software running.
This indicates interference by other software while the HostWriter is updating the AppHost.

The current implementation retries the resource update if an update because the device or drive is locked (say by an antivurus) HRESULT 0x21 and 0x6C.
However, the failures reported have errors 0x5 (Access violation) and 0x6# (Open failed).
Windows/Defender team said that file-locking with these error-codes is not expected.
However, different AVs work differently about examining files.

We believe that the correct fix for this issue is to complete:

To implement #3828 and #3829
Ship AppHost with an extension/permissions not indicating an executable.
However the above is a fairly large change for servicing .net core 3.1.

So, this change implements a simpler fix intended for servicing 3.1 branch:
Always retry the resource-update on Win32 error, unless the failure is a knwon irrecoverable code (listed a few error codes relevent to File IO).

This change may cause unnecessary retries on legitimate failures (about 50 seconds).
But such cases are rare, because the SDK supplies the apphost, and the HostModel itself creates the file to update.

Fixes #3832
@robkuz
Copy link

robkuz commented Feb 27, 2020

Is there a date when this will be released.
It is becoming a real issue for me

@robkuz
Copy link

robkuz commented Feb 27, 2020

looks like I found the prime suspect (at least in my case). It seems like Dropbox is interfering with the filesystem in a big way and therefore with createAppHost
I did run my deploy script which cleans, builds, runs tests, rebuilds, runs partial tests, cleans etc. multiple with either Dropbox sync enabled or disabled. (4 times without and 2 times with) and the results seem pretty clear: whenever I run it with dropbox sync enabled my rather extensive build fails always. if I run it without dropbox sync the build succeeds (4 out of 4).
As a side note - my dropbox account is really, really big (couple of 100K files).
Maybe someone can get into contact with someone from Dropbox?

@swaroop-sridhar
Copy link
Contributor

Is there a date when this will be released.

@robkuz I think this fix will make it into the April servicing release.

swaroop-sridhar added a commit to swaroop-sridhar/core-setup that referenced this issue Feb 28, 2020
dotnet/runtime#3832

Building a WinExe with resources fails non-deterministically

Several customers have observed failure during resource update when the HostModel updates the AppHost (to transfer resources from the managed app).
The failure is not detereminisitc, not reproducible on our machines, and depends on specific computers/software running.
This indicates interference by other software while the HostWriter is updating the AppHost.

The current implementation retries the resource update if an update because the device or drive is locked (say by an antivurus) HRESULT 0x21 and 0x6C. However, the failures reported have errors 0x5 (Access violation) and 0x6# (Open failed). Windows/Defender team said that file-locking with these error-codes is not expected.
However, different AVs work differently about examining files.

We believe that the correct fix for this issue is to complete:

* To implement dotnet#3828 and dotnet#3829
* Ship AppHost with an extension/permissions not indicating an executable.

However the above is a fairly large change for servicing .net core 3.1.

So, this change implements a simpler fix intended for servicing 3.1 branch: Always retry the resource-update on Win32 error. While this may cause unnecessary retries on legitimate failures (ex: file missing) such cases are rare, because the SDK supplies the apphost, and the HostModel itself creates the file to update.

Low

dotnet/runtime#32347
swaroop-sridhar added a commit to swaroop-sridhar/core-setup that referenced this issue Feb 28, 2020
dotnet/runtime#3832

Building a WinExe with resources fails non-deterministically

Several customers have observed failure during resource update when the HostModel updates the AppHost (to transfer resources from the managed app).
The failure is not detereminisitc, not reproducible on our machines, and depends on specific computers/software running.
This indicates interference by other software while the HostWriter is updating the AppHost.

The current implementation retries the resource update if an update because the device or drive is locked (say by an antivurus) HRESULT 0x21 and 0x6C. However, the failures reported have errors 0x5 (Access violation) and 0x6# (Open failed). Windows/Defender team said that file-locking with these error-codes is not expected.
However, different AVs work differently about examining files.

We believe that the correct fix for this issue is to complete:

* To implement dotnet#3828 and dotnet#3829
* Ship AppHost with an extension/permissions not indicating an executable.

However the above is a fairly large change for servicing .net core 3.1.

So, this change implements a simpler fix intended for servicing 3.1 branch: Always retry the resource-update on Win32 error. While this may cause unnecessary retries on legitimate failures (ex: file missing) such cases are rare, because the SDK supplies the apphost, and the HostModel itself creates the file to update.

Low

dotnet/runtime#32347
@Brend-Smits
Copy link

I know this issue has been closed // a fix is planned.
I just want to chip in and let others know that thanks to @robkuz I realized that in my case it was caused by Synology Drive. I recommend others having this issue to check if anything is syncing the directory to some external file service like Dropbox, Google Drive or a NAS.

Thanks all, this resolved my issues 😄

Anipik pushed a commit to dotnet/core-setup that referenced this issue Mar 25, 2020
dotnet/runtime#3832

Building a WinExe with resources fails non-deterministically

Several customers have observed failure during resource update when the HostModel updates the AppHost (to transfer resources from the managed app).
The failure is not detereminisitc, not reproducible on our machines, and depends on specific computers/software running.
This indicates interference by other software while the HostWriter is updating the AppHost.

The current implementation retries the resource update if an update because the device or drive is locked (say by an antivurus) HRESULT 0x21 and 0x6C. However, the failures reported have errors 0x5 (Access violation) and 0x6# (Open failed). Windows/Defender team said that file-locking with these error-codes is not expected.
However, different AVs work differently about examining files.

We believe that the correct fix for this issue is to complete:

* To implement #3828 and #3829
* Ship AppHost with an extension/permissions not indicating an executable.

However the above is a fairly large change for servicing .net core 3.1.

So, this change implements a simpler fix intended for servicing 3.1 branch: Always retry the resource-update on Win32 error. While this may cause unnecessary retries on legitimate failures (ex: file missing) such cases are rare, because the SDK supplies the apphost, and the HostModel itself creates the file to update.

Low

dotnet/runtime#32347
@robinwilson16
Copy link

I'm getting the same error or another saying the cloud operation failed when project is hosted in a OneDrive folder.
I've now set it to always keep the files on this device so will see if that helps. I have had projects on OneDrive with no issues before.

@AMassani
Copy link

AMassani commented May 1, 2020

I know this issue has been closed // a fix is planned.
I just want to chip in and let others know that thanks to @robkuz I realized that in my case it was caused by Synology Drive. I recommend others having this issue to check if anything is syncing the directory to some external file service like Dropbox, Google Drive or a NAS.

Thanks all, this resolved my issues 😄

@ghost ghost locked as resolved and limited conversation to collaborators Dec 12, 2020
@ericstj ericstj reopened this Feb 5, 2021
@ericstj
Copy link
Member

ericstj commented Feb 5, 2021

Folks are still reporting this. We shouldn't be relying on retry as a solution here. There is a correct way for build tools to make file changes: only ever write using the very first created handle. Once a file is closed, only ever open for read. If you need to write again, make a copy maintaining the open handle and write to that handle. In this way you can never be broken by AV-interference.

@wli3 wli3 removed their assignment Feb 9, 2021
@agocke
Copy link
Member

agocke commented Jul 28, 2021

I believe this has been fixed by #48774

@agocke agocke closed this as completed Jul 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-HostModel Microsoft.NET.HostModel issues
Projects
None yet