Skip to content

Commit c4ab2a7

Browse files
HostModel: Retry ResourceUpdate on Win32 error (#32347)
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
1 parent ef3489f commit c4ab2a7

1 file changed

Lines changed: 34 additions & 7 deletions

File tree

  • src/installer/managed/Microsoft.NET.HostModel/AppHost

src/installer/managed/Microsoft.NET.HostModel/AppHost/RetryUtil.cs

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,43 @@ public static void RetryOnIOError(Action func)
4141

4242
public static void RetryOnWin32Error(Action func)
4343
{
44-
bool IsWin32FileLockError(int hresult)
44+
bool IsKnownIrrecoverableError(int hresult)
4545
{
4646
// Error codes are defined in winerror.h
47-
const int ErrorLockViolation = 33;
48-
const int ErrorDriveLocked = 108;
49-
5047
// The error code is stored in the lowest 16 bits of the HResult
51-
int errorCode = hresult & 0xffff;
5248

53-
return errorCode == ErrorLockViolation || errorCode == ErrorDriveLocked;
49+
switch (hresult & 0xffff)
50+
{
51+
case 0x00000001: // ERROR_INVALID_FUNCTION
52+
case 0x00000002: // ERROR_FILE_NOT_FOUND
53+
case 0x00000003: // ERROR_PATH_NOT_FOUND
54+
case 0x00000006: // ERROR_INVALID_HANDLE
55+
case 0x00000008: // ERROR_NOT_ENOUGH_MEMORY
56+
case 0x0000000B: // ERROR_BAD_FORMAT
57+
case 0x0000000E: // ERROR_OUTOFMEMORY
58+
case 0x0000000F: // ERROR_INVALID_DRIVE
59+
case 0x00000012: // ERROR_NO_MORE_FILES
60+
case 0x00000035: // ERROR_BAD_NETPATH
61+
case 0x00000057: // ERROR_INVALID_PARAMETER
62+
case 0x00000071: // ERROR_NO_MORE_SEARCH_HANDLES
63+
case 0x00000072: // ERROR_INVALID_TARGET_HANDLE
64+
case 0x00000078: // ERROR_CALL_NOT_IMPLEMENTED
65+
case 0x0000007B: // ERROR_INVALID_NAME
66+
case 0x0000007C: // ERROR_INVALID_LEVEL
67+
case 0x0000007D: // ERROR_NO_VOLUME_LABEL
68+
case 0x0000009A: // ERROR_LABEL_TOO_LONG
69+
case 0x000000A0: // ERROR_BAD_ARGUMENTS
70+
case 0x000000A1: // ERROR_BAD_PATHNAME
71+
case 0x000000CE: // ERROR_FILENAME_EXCED_RANGE
72+
case 0x000000DF: // ERROR_FILE_TOO_LARGE
73+
case 0x000003ED: // ERROR_UNRECOGNIZED_VOLUME
74+
case 0x000003EE: // ERROR_FILE_INVALID
75+
case 0x00000651: // ERROR_DEVICE_REMOVED
76+
return true;
77+
78+
default:
79+
return false;
80+
}
5481
}
5582

5683
for (int i = 1; i <= NumberOfRetries; i++)
@@ -61,7 +88,7 @@ bool IsWin32FileLockError(int hresult)
6188
break;
6289
}
6390
catch (HResultException hrex)
64-
when (i < NumberOfRetries && IsWin32FileLockError(hrex.Win32HResult))
91+
when (i < NumberOfRetries && !IsKnownIrrecoverableError(hrex.Win32HResult))
6592
{
6693
Thread.Sleep(NumMilliSecondsToWait);
6794
}

0 commit comments

Comments
 (0)