-
Notifications
You must be signed in to change notification settings - Fork 29
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
Add a retry attempt when copying files #245
Conversation
/// set. | ||
/// </summary> | ||
/// <returns>The value of DOTNET_ANDROID_FILE_WRITE_RETRY_ATTEMPTS or the default of DEFAULT_FILE_WRITE_RETRY_ATTEMPTS</returns> | ||
public static int GetFileWriteRetryAttempts () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made these public so we can use them from XA.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have an other environment variables like this? I wonder if they should go in a class like KnownEnvironment.cs
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't afaik.
$(LangVersion)=13 breaks CI: ``` Invalid option '13.0' for /langversion. Use '/langversion:?' to list supported values. ``` Let's try 12.0?
… by another process Fixes dotnet#25207 Context dotnet/android-tools#245 dotnet/android#9409 So there is a problem where the design time builds (DTB) of android sometimes lock files. This can happen when two processes try to write to the same file. This is not a great experience for our users as it just fails the build. So lets try a few things to fix this. 1. Move the Resizetizer output for a DTB into the android `$(IntermediateOutputPath)designtime` folder. This will keep the DTB files completely separate. This should prevent clashes. 2. Add some retry code to the `SkiaSharpTools.Save` method. This will catch `UnauthorizedAccessException` exceptions as well as specific `IOException` types (Access Denied and Sharing Violation). This will allow us to catch when this happens and retry the write. There is a small delay before attempting to write the file again. Note these code uses the Identical code as we are going to use in Android. We have introduced two new environment variables which can be used to control the new behavior. 1. `DOTNET_ANDROID_FILE_WRITE_RETRY_ATTEMPTS`. Integer, controls the number of times we try to write the file. The default is 10. 2. `DOTNET_ANDROID_FILE_WRITE_RETRY_DELAY_MS`. Integer, controls the delay in milliseconds between retry attempts. Default is 1000ms (or 1 second).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, this looks good to me, just had a couple comments.
/// set. | ||
/// </summary> | ||
/// <returns>The value of DOTNET_ANDROID_FILE_WRITE_RETRY_ATTEMPTS or the default of DEFAULT_FILE_WRITE_RETRY_ATTEMPTS</returns> | ||
public static int GetFileWriteRetryAttempts () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have an other environment variables like this? I wonder if they should go in a class like KnownEnvironment.cs
.
[Microsoft.Android.Build.BaseTasks] retry when copying files (#245)
Context: https://github.com/dotnet/android/issues/9133
Context: https://learn.microsoft.com/visualstudio/msbuild/copy-task?view=vs-2022
We sometimes get collisions between the Design-Time-Build (or
AntiVirus) and our main build. This can result in errors such as:
Error (active) XALNS7019 System.UnauthorizedAccessException: Access to the path 'D:\Projects\MauiApp2\obj\Debug\net9.0-android\android\assets\armeabi-v7a\MauiApp2.dll' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalDelete(String path, Boolean checkHost)
at Microsoft.Android.Build.Tasks.Files.CopyIfChanged(String source, String destination) in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/Files.cs:line 125
at Xamarin.Android.Tasks.MonoAndroidHelper.CopyAssemblyAndSymbols(String source, String destination) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs:line 344
at Xamarin.Android.Tasks.LinkAssembliesNoShrink.CopyIfChanged(ITaskItem source, ITaskItem destination) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tasks/LinkAssembliesNoShrink.cs:line 161
at Xamarin.Android.Tasks.LinkAssembliesNoShrink.RunTask() in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tasks/LinkAssembliesNoShrink.cs:line 76
at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25 MauiApp2 (net9.0-android) C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.99.0-preview.6.340\tools\Xamarin.Android.Common.targets 1407
If we look at the [MSBuild `<Copy/>` task][0] we see that it has a
retry system in the cases of `UnauthorizedAccessException` or
`IOException` when the code is `ACCESS_DENIED` or
`ERROR_SHARING_VIOLATION`. The `<Copy/>` task also has public
`Retries` and `RetryDelayMilliseconds` properties to control behavior.
Duplicate that kind of logic into our `Files.Copy*IfChanged()` helper
methods. This should give our builds a bit more resiliency to these
kinds of issues.
Instead of adding new `Files.Copy*IfChanged()` method overloads which
accept "retries" and "retryDelay" parameters, we instead use
environment variables to allow overriding these values:
* `DOTNET_ANDROID_FILE_WRITE_RETRY_ATTEMPTS`: The number of times
to try to retry a copy operation; corresponds to the
`Copy.Retries` MSBuild task property.
The default value is 10.
* `DOTNET_ANDROID_FILE_WRITE_RETRY_DELAY_MS`: The amount of time,
in milliseconds, to delay between attempted copies; corresponds
to the `Copy.RetryDelayMilliseconds` MSBuild task property.
The default value is 1000 ms.
[0]: https://github.com/dotnet/msbuild/blob/main/src/Tasks/Copy.cs#L897 |
Co-authored-by: Jonathan Peppers <jonathan.peppers@microsoft.com>
Yes?
I'm not sure what a |
Changes: dotnet/android-tools@ab2165d...60fae19 * dotnet/android-tools@60fae19: [Microsoft.Android.Build.BaseTasks] retry when copying files (dotnet/android-tools#245)
… by another process Fixes dotnet#25207 Context dotnet/android-tools#245 dotnet/android#9409 So there is a problem where the design time builds (DTB) of android sometimes lock files. This can happen when two processes try to write to the same file. This is not a great experience for our users as it just fails the build. So lets try a few things to fix this. 1. Move the Resizetizer output for a DTB into the android `$(IntermediateOutputPath)designtime` folder. This will keep the DTB files completely separate. This should prevent clashes. 2. Add some retry code to the `SkiaSharpTools.Save` method. This will catch `UnauthorizedAccessException` exceptions as well as specific `IOException` types (Access Denied and Sharing Violation). This will allow us to catch when this happens and retry the write. There is a small delay before attempting to write the file again. Note these code uses the Identical code as we are going to use in Android. We have introduced two new environment variables which can be used to control the new behavior. 1. `DOTNET_ANDROID_FILE_WRITE_RETRY_ATTEMPTS`. Integer, controls the number of times we try to write the file. The default is 10. 2. `DOTNET_ANDROID_FILE_WRITE_RETRY_DELAY_MS`. Integer, controls the delay in milliseconds between retry attempts. Default is 1000ms (or 1 second).
Changes: dotnet/android-tools@ab2165d...60fae19 * dotnet/android-tools@60fae19: [Microsoft.Android.Build.BaseTasks] retry when copying files (dotnet/android-tools#245)
… by another process Fixes dotnet#25207 Context dotnet/android-tools#245 dotnet/android#9409 So there is a problem where the design time builds (DTB) of android sometimes lock files. This can happen when two processes try to write to the same file. This is not a great experience for our users as it just fails the build. So lets try a few things to fix this. 1. Move the Resizetizer output for a DTB into the android `$(IntermediateOutputPath)designtime` folder. This will keep the DTB files completely separate. This should prevent clashes. 2. Add some retry code to the `SkiaSharpTools.Save` method. This will catch `UnauthorizedAccessException` exceptions as well as specific `IOException` types (Access Denied and Sharing Violation). This will allow us to catch when this happens and retry the write. There is a small delay before attempting to write the file again. Note these code uses the Identical code as we are going to use in Android. We have introduced two new environment variables which can be used to control the new behavior. 1. `DOTNET_ANDROID_FILE_WRITE_RETRY_ATTEMPTS`. Integer, controls the number of times we try to write the file. The default is 10. 2. `DOTNET_ANDROID_FILE_WRITE_RETRY_DELAY_MS`. Integer, controls the delay in milliseconds between retry attempts. Default is 1000ms (or 1 second).
Changes: dotnet/android-tools@ab2165d...60fae19 * dotnet/android-tools@60fae19: [Microsoft.Android.Build.BaseTasks] retry when copying files (dotnet/android-tools#245)
Changes: dotnet/android-tools@ab2165d...60fae19 * dotnet/android-tools@60fae19: [Microsoft.Android.Build.BaseTasks] retry when copying files (dotnet/android-tools#245) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
… by another process Fixes dotnet#25207 Context dotnet/android-tools#245 dotnet/android#9409 So there is a problem where the design time builds (DTB) of android sometimes lock files. This can happen when two processes try to write to the same file. This is not a great experience for our users as it just fails the build. So lets try a few things to fix this. 1. Move the Resizetizer output for a DTB into the android `$(IntermediateOutputPath)designtime` folder. This will keep the DTB files completely separate. This should prevent clashes. 2. Add some retry code to the `SkiaSharpTools.Save` method. This will catch `UnauthorizedAccessException` exceptions as well as specific `IOException` types (Access Denied and Sharing Violation). This will allow us to catch when this happens and retry the write. There is a small delay before attempting to write the file again. Note these code uses the Identical code as we are going to use in Android. We have introduced two new environment variables which can be used to control the new behavior. 1. `DOTNET_ANDROID_FILE_WRITE_RETRY_ATTEMPTS`. Integer, controls the number of times we try to write the file. The default is 10. 2. `DOTNET_ANDROID_FILE_WRITE_RETRY_DELAY_MS`. Integer, controls the delay in milliseconds between retry attempts. Default is 1000ms (or 1 second).
… by another process Fixes dotnet#25207 Context dotnet/android-tools#245 dotnet/android#9409 So there is a problem where the design time builds (DTB) of android sometimes lock files. This can happen when two processes try to write to the same file. This is not a great experience for our users as it just fails the build. So lets try a few things to fix this. 1. Move the Resizetizer output for a DTB into the android `$(IntermediateOutputPath)designtime` folder. This will keep the DTB files completely separate. This should prevent clashes. 2. Add some retry code to the `SkiaSharpTools.Save` method. This will catch `UnauthorizedAccessException` exceptions as well as specific `IOException` types (Access Denied and Sharing Violation). This will allow us to catch when this happens and retry the write. There is a small delay before attempting to write the file again. Note these code uses the Identical code as we are going to use in Android. We have introduced two new environment variables which can be used to control the new behavior. 1. `DOTNET_ANDROID_FILE_WRITE_RETRY_ATTEMPTS`. Integer, controls the number of times we try to write the file. The default is 10. 2. `DOTNET_ANDROID_FILE_WRITE_RETRY_DELAY_MS`. Integer, controls the delay in milliseconds between retry attempts. Default is 1000ms (or 1 second).
… by another process Fixes dotnet#25207 Context dotnet/android-tools#245 dotnet/android#9409 So there is a problem where the design time builds (DTB) of android sometimes lock files. This can happen when two processes try to write to the same file. This is not a great experience for our users as it just fails the build. So lets try a few things to fix this. 1. Move the Resizetizer output for a DTB into the android `$(IntermediateOutputPath)designtime` folder. This will keep the DTB files completely separate. This should prevent clashes. 2. Add some retry code to the `SkiaSharpTools.Save` method. This will catch `UnauthorizedAccessException` exceptions as well as specific `IOException` types (Access Denied and Sharing Violation). This will allow us to catch when this happens and retry the write. There is a small delay before attempting to write the file again. Note these code uses the Identical code as we are going to use in Android. We have introduced two new environment variables which can be used to control the new behavior. 1. `DOTNET_ANDROID_FILE_WRITE_RETRY_ATTEMPTS`. Integer, controls the number of times we try to write the file. The default is 10. 2. `DOTNET_ANDROID_FILE_WRITE_RETRY_DELAY_MS`. Integer, controls the delay in milliseconds between retry attempts. Default is 1000ms (or 1 second).
… by another process Fixes dotnet#25207 Context dotnet/android-tools#245 dotnet/android#9409 So there is a problem where the design time builds (DTB) of android sometimes lock files. This can happen when two processes try to write to the same file. This is not a great experience for our users as it just fails the build. So lets try a few things to fix this. 1. Move the Resizetizer output for a DTB into the android `$(IntermediateOutputPath)designtime` folder. This will keep the DTB files completely separate. This should prevent clashes. 2. Add some retry code to the `SkiaSharpTools.Save` method. This will catch `UnauthorizedAccessException` exceptions as well as specific `IOException` types (Access Denied and Sharing Violation). This will allow us to catch when this happens and retry the write. There is a small delay before attempting to write the file again. Note these code uses the Identical code as we are going to use in Android. We have introduced two new environment variables which can be used to control the new behavior. 1. `DOTNET_ANDROID_FILE_WRITE_RETRY_ATTEMPTS`. Integer, controls the number of times we try to write the file. The default is 10. 2. `DOTNET_ANDROID_FILE_WRITE_RETRY_DELAY_MS`. Integer, controls the delay in milliseconds between retry attempts. Default is 1000ms (or 1 second).
… by another process Fixes dotnet#25207 Context dotnet/android-tools#245 dotnet/android#9409 So there is a problem where the design time builds (DTB) of android sometimes lock files. This can happen when two processes try to write to the same file. This is not a great experience for our users as it just fails the build. So lets try a few things to fix this. 1. Move the Resizetizer output for a DTB into the android `$(IntermediateOutputPath)designtime` folder. This will keep the DTB files completely separate. This should prevent clashes. 2. Add some retry code to the `SkiaSharpTools.Save` method. This will catch `UnauthorizedAccessException` exceptions as well as specific `IOException` types (Access Denied and Sharing Violation). This will allow us to catch when this happens and retry the write. There is a small delay before attempting to write the file again. Note these code uses the Identical code as we are going to use in Android. We have introduced two new environment variables which can be used to control the new behavior. 1. `DOTNET_ANDROID_FILE_WRITE_RETRY_ATTEMPTS`. Integer, controls the number of times we try to write the file. The default is 10. 2. `DOTNET_ANDROID_FILE_WRITE_RETRY_DELAY_MS`. Integer, controls the delay in milliseconds between retry attempts. Default is 1000ms (or 1 second).
… by another process Fixes dotnet#25207 Context dotnet/android-tools#245 dotnet/android#9409 So there is a problem where the design time builds (DTB) of android sometimes lock files. This can happen when two processes try to write to the same file. This is not a great experience for our users as it just fails the build. So lets try a few things to fix this. 1. Move the Resizetizer output for a DTB into the android `$(IntermediateOutputPath)designtime` folder. This will keep the DTB files completely separate. This should prevent clashes. 2. Add some retry code to the `SkiaSharpTools.Save` method. This will catch `UnauthorizedAccessException` exceptions as well as specific `IOException` types (Access Denied and Sharing Violation). This will allow us to catch when this happens and retry the write. There is a small delay before attempting to write the file again. Note these code uses the Identical code as we are going to use in Android. We have introduced two new environment variables which can be used to control the new behavior. 1. `DOTNET_ANDROID_FILE_WRITE_RETRY_ATTEMPTS`. Integer, controls the number of times we try to write the file. The default is 10. 2. `DOTNET_ANDROID_FILE_WRITE_RETRY_DELAY_MS`. Integer, controls the delay in milliseconds between retry attempts. Default is 1000ms (or 1 second).
… by another process Fixes dotnet#25207 Context dotnet/android-tools#245 dotnet/android#9409 So there is a problem where the design time builds (DTB) of android sometimes lock files. This can happen when two processes try to write to the same file. This is not a great experience for our users as it just fails the build. So lets try a few things to fix this. 1. Move the Resizetizer output for a DTB into the android `$(IntermediateOutputPath)designtime` folder. This will keep the DTB files completely separate. This should prevent clashes. 2. Add some retry code to the `SkiaSharpTools.Save` method. This will catch `UnauthorizedAccessException` exceptions as well as specific `IOException` types (Access Denied and Sharing Violation). This will allow us to catch when this happens and retry the write. There is a small delay before attempting to write the file again. Note these code uses the Identical code as we are going to use in Android. We have introduced two new environment variables which can be used to control the new behavior. 1. `DOTNET_ANDROID_FILE_WRITE_RETRY_ATTEMPTS`. Integer, controls the number of times we try to write the file. The default is 10. 2. `DOTNET_ANDROID_FILE_WRITE_RETRY_DELAY_MS`. Integer, controls the delay in milliseconds between retry attempts. Default is 1000ms (or 1 second).
… by another process (#25374) * Creating .NET MAUI Project sometimes causes error *.png is being used by another process Fixes #25207 Context dotnet/android-tools#245 dotnet/android#9409 So there is a problem where the design time builds (DTB) of android sometimes lock files. This can happen when two processes try to write to the same file. This is not a great experience for our users as it just fails the build. So lets try a few things to fix this. 1. Move the Resizetizer output for a DTB into the android `$(IntermediateOutputPath)designtime` folder. This will keep the DTB files completely separate. This should prevent clashes. 2. Add some retry code to the `SkiaSharpTools.Save` method. This will catch `UnauthorizedAccessException` exceptions as well as specific `IOException` types (Access Denied and Sharing Violation). This will allow us to catch when this happens and retry the write. There is a small delay before attempting to write the file again. Note these code uses the Identical code as we are going to use in Android. We have introduced two new environment variables which can be used to control the new behavior. 1. `DOTNET_ANDROID_FILE_WRITE_RETRY_ATTEMPTS`. Integer, controls the number of times we try to write the file. The default is 10. 2. `DOTNET_ANDROID_FILE_WRITE_RETRY_DELAY_MS`. Integer, controls the delay in milliseconds between retry attempts. Default is 1000ms (or 1 second). * Back out the change which moves the 'r' directory to designtime * Slight change to make sure we do not loop forever * Exit if all is well
Context dotnet/android#9133.
We get collisions between the DTB (or AV) and our main build. This can result in the following error
If we look at the MSBuild Copy task we see that it has a retry system in the cases of
UnauthorizedAccessException
orIOException
when the code isACCESS_DENIED
orERROR_SHARING_VIOLATION
. So lets duplicate that kind of logic in ourCopy*IfChanged
helper methods. This should give our builds a bit more resiliency to these kinds of issues.